如何将Python的”wheel”导入SnowFlake作为包

huangapple go评论56阅读模式
英文:

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:

  1. 从pypi.org下载轮子(wheel)。
  2. 创建wheel_loader.py脚本,就像Medium文章中所示。
  3. 使用SnowSQL,将轮子和wheel loader脚本上传到stage。
  4. 创建Python UDF(步骤5-7)。
  5. 导入轮子和脚本:
imports=('@PYTHON_PACKAGES/wheel_loader.py',
         '@PYTHON_PACKAGES/TheWheelFileName.whl'
        )
  1. 在你的处理函数中,运行轮子加载脚本:
wheel_loader.load('TheWheelFileName.whl')
  1. 在轮子加载后,从轮子包中导入:
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)
$$;
英文:
  1. Download the wheel from pypi.org
  2. Create the wheel_loader.py script as in the Medium article
  3. Using SnowSQL, PUT the wheel and wheel loader script into the stage
  4. Create the Python UDF (steps 5-7)
  5. Import the wheel and script
imports=('@PYTHON_PACKAGES/wheel_loader.py',
         '@PYTHON_PACKAGES/TheWheelFileName.whl'
        )
  1. In your handler function, run the wheel loader script
    wheel_loader.load('TheWheelFileName.whl')
  2. 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)
$$;

huangapple
  • 本文由 发表于 2023年5月8日 02:41:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76195687.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定