I know very similar questions have been asked, but all attempts to import this non-Anaconda package into a Snowflake Python worksheet give the error “ModuleNotFoundError: No module named…”.
- I used
pip download Office365-REST-Python-client
and zipped all of the wheel files together. - Uploaded the file “Office365_rest_python_client_2_5_11.zip” to a stage.
- Started a Python worksheet in the same db and schema as the stage, went to the packages menu and and loaded the zip file. Here’s a screen shot to show it worked:
- At this point the Snowflake docs state that I cannot use
session.add_import
,session.add_packages
orsession.add_requirements
to add packages. “Instead, you add those files to a stage and reference them in your code.”
But still, import Office365_rest_python_client_2_5_11
, or the real name of the package that I’ve used elsewhere import office365.sharepoint.client_context
return the same “ModuleNotFoundError”.
I’ve also tried to make sure the stage is in the sys.path with:
session.custom_packages_usage_config = {"enabled": True}
import_dir = sys._xoptions.get("snowflake_import_directory")
sys.path.append(import_dir + "Office365_rest_python_client_2_5_11.zip")
None of which make a difference. It also makes no difference if the import is with the rest of the imports at the top, or inside the main
handler. I must be missing some conceptual piece of this workflow. Has anyone successfully loaded a non-Anaconda to a worksheet specifically?
Here’s the entire worksheet:
import sys
import snowflake.snowpark as sp
import snowflake.snowpark.functions as sff
def main(session):
session.custom_packages_usage_config = {"enabled": True}
import_dir = sys._xoptions.get("snowflake_import_directory")
sys.path.append(import_dir + "Office365_rest_python_client_2_5_11.zip")
import Office365_rest_python_client_2_5_11 as shrp
dataframe = session.table('information_schema.packages')
.filter(sff.col("language") == 'python')
.filter(sff.col("runtime_version") == '3.11')
return(dataframe)
Many thanks!