简体   繁体   English

如何在Python3.5中制作Jupyter Notebook导入包

[英]How to make Jupyter Notebook import packages in Python3.5

I have several packages being imported perfectly in my Python 3.5. 我有一些软件包可以完美地导入我的Python 3.5中。 But not in my Jupyter Notebook... When i try to Import those packages in Jupyter i get and error of module not found. 但是不在我的Jupyter笔记本中...当我尝试在Jupyter中导入那些软件包时,我得到了并且找不到模块错误。 Is there a way to make Jupyter load my Python 3.5 as a kernel... or something similar. 有没有办法让Jupyter将我的Python 3.5加载为内核……或类似的东西。 I'm working in a virtual environment. 我在虚拟环境中工作。 Already tried to reinstall the packages again in my virtual env But no success. 已经尝试在我的虚拟环境中再次重新安装软件包,但是没有成功。

Try to install the packages inside a jupyter notebook cell like this: 尝试将软件包安装在jupyter笔记本计算机中,如下所示:

!pip install package

So you are sure that the packages are installed in jupyter's environment 因此,您确定软件包已安装在jupyter的环境中

If you install the ipython kernel form inside the virtualenv, you can guarantee that the packages are imported to the jupyter if they are imported to this env. 如果将ipython内核形式安装在virtualenv中,则可以保证将软件包导入到jupyter中(如果已将软件包导入到该env中)。 Also, if you use this approach, you do not need to activate the virtualenv every time you run the jupyter, because jupyter does it automatically. 另外,如果使用此方法,则无需每次运行jupyter时都激活virtualenv,因为jupyter会自动执行。

$ python -m venv projectname
$ source projectname/bin/activate
(venv) $ pip install ipykernel
(venv) $ ipython kernel install --user --name=projectname
(venv) $ pip install {package needed to install}

Source: Using jupyter notebooks with a virtual environment 资料来源: 在虚拟环境中使用jupyter笔记本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM