英文:
How to Import a Python "wheel" into SnowFlake as Package
问题
如何将一个“wheel”文件导入到SnowFlake中?
我想要导入一个从PyPi下载的Python“wheel”文件,但不确定该如何操作。
我尝试了以下链接中的一些指导,但没有成功:
https://medium.com/snowflake/running-pip-packages-in-snowflake-d43581a67439
英文:
Can someone show me how to import a "wheel" file into SnowFlake?
I would like to import a Python "wheel" file that has been downloaded from PyPi, but not sure how to go about it.
I tried some guidance from the following link but no luck
https://medium.com/snowflake/running-pip-packages-in-snowflake-d43581a67439
答案1
得分: 1
Sure, here are the translated parts of the content you provided:
- 从pypi.org下载轮子(wheel)。
- 创建wheel_loader.py脚本,就像Medium文章中所示。
- 使用SnowSQL,将轮子和wheel loader脚本上传到stage。
- 创建Python UDF(步骤5-7)。
- 导入轮子和脚本:
imports=('@PYTHON_PACKAGES/wheel_loader.py',
'@PYTHON_PACKAGES/TheWheelFileName.whl'
)
- 在你的处理函数中,运行轮子加载脚本:
wheel_loader.load('TheWheelFileName.whl')
- 在轮子加载后,从轮子包中导入:
from TheWheelPackage import some_function, another_function
实际上,似乎并不总是需要wheel loader脚本。我有一个可用的UDF,它只是导入轮子并将其添加到系统路径中。不清楚在何时需要wheel loader方法,何时简单的导入和添加到系统路径就足够了。
create or replace function ULID()
returns string
language python
volatile
runtime_version = '3.8'
imports=('@PYTHON_PACKAGES/python_ulid-1.1.0-py3-none-any.whl',)
handler = 'ulid'
as
$$
import sys
import_dir = sys._xoptions.get("snowflake_import_directory")
sys.path.append(import_dir + '/python_ulid-1.1.0-py3-none-any.whl')
def ulid():
import ulid
ulid = ulid.ULID()
return str(ulid)
$$;
英文:
- Download the wheel from pypi.org
- Create the wheel_loader.py script as in the Medium article
- Using SnowSQL, PUT the wheel and wheel loader script into the stage
- Create the Python UDF (steps 5-7)
- Import the wheel and script
imports=('@PYTHON_PACKAGES/wheel_loader.py',
'@PYTHON_PACKAGES/TheWheelFileName.whl'
)
- In your handler function, run the wheel loader script
wheel_loader.load('TheWheelFileName.whl')
- After the wheel load, import from the wheel package
from TheWheelPackage import some_function, another_function
Actually the wheel loader script does not appear to always be required. I have a working UDF that simply imports the wheel and adds it to the system path. It is unclear to me when the wheel loader approach may be required and when a simple import/add to system path may suffice.
create or replace function ULID()
returns string
language python
volatile
runtime_version = '3.8'
imports=('@PYTHON_PACKAGES/python_ulid-1.1.0-py3-none-any.whl')
handler = 'ulid'
as
$$
import sys
import_dir = sys._xoptions.get("snowflake_import_directory")
sys.path.append(import_dir + '/python_ulid-1.1.0-py3-none-any.whl')
def ulid():
import ulid
ulid = ulid.ULID()
return str(ulid)
$$;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论