在SnowFlake中导入Python包以在Python工作表中使用。

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

Import Python Packages in SnowFlake to be Used Python Worksheets

问题

我已成功按照以下指南安装了一个Python包:

https://medium.com/snowflake/running-pip-packages-in-snowflake-d43581a67439

然而,结果与我预期的完全相同。

我希望在将Python Wheel导入SnowFlake后,该包会出现在这里

在SnowFlake中导入Python包以在Python工作表中使用。

但是,正如您所见,没有添加任何包。

我相信,如果按照图像中所示添加了该包,我将能够从SnowFlake Python工作表中执行以下代码行:

from faker_biology.physiology import CellType, Organ, Organelle
from faker import Faker

但我一直收到ModuleNotFoundError错误。

所以,是否有人可以告诉我如何添加一个可以从SnowFlake Python工作表中访问的Python包呢?

英文:

I have successfully installed a Python package using the following guide:

https://medium.com/snowflake/running-pip-packages-in-snowflake-d43581a67439

However, the outcome is exactly what I was expecting.

I was hoping that after importing the Python Wheel into SnowFlake the package would appear here

在SnowFlake中导入Python包以在Python工作表中使用。

But as you can see no packages were added.

I believe if the package was added as shown in the image I would be able to execute the following lines of code from a SnowFlake Python Worksheet:

from faker_biology.physiology import CellType, Organ, Organelle
from faker import Faker

But I keep on getting the error ModuleNotFoundError

So, can someone let me know how to add a Python Package that will accessible from a SnowFlake Python Worksheet?

答案1

得分: 1

I could run it inside Python worksheet without any issues:

import snowflake.snowpark as snowpark
from faker import Faker
import wheel_loader

def fake(locale,provider,parameters):
    wheel_loader.load('faker_biology-0.6.0-py3-none-any.whl')
    from faker_biology.physiology import CellType
    if type(parameters).__name__=='sqlNullWrapper':
        parameters = {}
    fake = Faker(locale=locale)
    fake.add_provider(CellType)
    return fake.format(formatter=provider,**parameters)

def main(session: snowpark.Session): 
    return fake('en_US','celltype',{})

Output:

|PYTHON_WORKSHEET|
|---|
|Starburst amacrine cells|

Anaconda package:

在SnowFlake中导入Python包以在Python工作表中使用。

Stage Packages:

在SnowFlake中导入Python包以在Python工作表中使用。

Output:

在SnowFlake中导入Python包以在Python工作表中使用。

英文:

I could run it inside Python worksheet without any issues:

import snowflake.snowpark as snowpark

from faker import Faker
import wheel_loader
    
def fake(locale,provider,parameters):
    wheel_loader.load('faker_biology-0.6.0-py3-none-any.whl')

    from faker_biology.physiology import CellType
      
    if type(parameters).__name__=='sqlNullWrapper':
        parameters = {}
    fake = Faker(locale=locale)
    fake.add_provider(CellType)
    return fake.format(formatter=provider,**parameters)

def main(session: snowpark.Session): 
    return fake('en_US','celltype',{})

Output:

PYTHON_WORKSHEET
Starburst amacrine cells

Anaconda package:

在SnowFlake中导入Python包以在Python工作表中使用。

Stage Packages:

在SnowFlake中导入Python包以在Python工作表中使用。

Output:

在SnowFlake中导入Python包以在Python工作表中使用。

huangapple
  • 本文由 发表于 2023年5月10日 21:10:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76218843.html
匿名

发表评论

匿名网友

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

确定