在docker上运行的Jupyter Notebook中出现以下错误。
NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:snowflake`
我正在运行以下
from sqlalchemy import create_engine
engine = create_engine(
f'snowflake://asd:asd@bla/analytics/public?warehouse=general&role=analyst'
)
在笔记本中,我可以执行以下命令并使代码工作,结果如下:
!python3 --version
!echo '---'
!cat test.py
!echo '---'
!python3 test.py
Python 3.6.8 :: Anaconda, Inc.
---
from sqlalchemy import create_engine
engine = create_engine(
f'snowflake://asd:asd@bla/analytics/public?warehouse=general&role=analyst'
)
print(engine)
---
Engine(snowflake://asd:***@bla/analytics/public?role=analyst&warehouse=general)
但是,从Jupyter笔记本中运行相同的create_engine()会返回错误:NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:snowflake
。
我真的很困惑为什么会发生这种情况。
我什至在我的Dockerfile中添加了pip install --upgrade snowflake-sqlaclchemy
:
# Start from a core stack version https://jupyter-docker-stacks.readthedocs.io/en/latest/using/recipes.html
FROM jupyter/tensorflow-notebook
# Install in the default python3 environment
COPY requirements.txt /tmp/
RUN pip install --requirement /tmp/requirements.txt && \
pip install --upgrade snowflake-sqlalchemy && \
fix-permissions $CONDA_DIR && \
fix-permissions /home/$NB_USER
答案 0 :(得分:0)
在笔记本中添加以下内容即可正常工作
破解方法:
!python3 -m pip install --upgrade snowflake-sqlalchemy
exit()
#once complete, go to Kernel>Restart&Clear Output
更好的解决方案:
修改Dockerfile后,我没有运行docker build --rm -t jupyter/sme-datascience-notebook .
,此问题已解决