Python doesn't see packages with Jupyter Notebook

一世执手 提交于 2020-02-02 11:41:12

问题


I use Jupyter Notebook with a virtual environment. I have a dependency installed, but can't import it:

cell 1:
!pip3 install sent2vec

Requirement already satisfied: sent2vec in 
venv/lib/python3.7/site-packages (0.0.0)

cell 2:
import sent2vec

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-5-06231d291a17> in <module>
----> 1 import sent2vec

ModuleNotFoundError: No module named 'sent2vec'

How this can happen? How to fix this?

> pip3 list
Package      Version  
------------ ---------
certifi      2019.9.11
chardet      3.0.4    
Cython       0.29.14  
idna         2.8      
joblib       0.14.0   
langdetect   1.0.7    
nltk         3.4.4    
numpy        1.17.1   
pip          19.3.1   
requests     2.22.0   
scikit-learn 0.21.3   
scipy        1.3.2    
sent2vec     0.0.0    
setuptools   41.6.0   
six          1.13.0   
urllib3      1.25.7   
wheel        0.33.6

回答1:


You'll note that jupyter is not listed in your installed packages. That means you're running it from a different virtual environment. As I mentioned in the comment responding to your question, you can run which jupyter to find out where your Jupyter Notebook application is being run from (assuming you're on a *NIX system); in this case, it won't be from the python3.7 virtual environment that shows up in your first code block.

To resolve the issue, you simply need to run pip3 install jupyter, then retry running jupyter notebook.

Alternatively, you can add your virtual environment as a kernel so that it can be selected when you're running Jupyter from your original environment. To do this, you would run (assuming pip is connected to your original environment):

pip install ipykernel
ipython kernel install --user --name=<insert name of your venv>

You should then be able to select that venv as a kernel on new notebooks. (Source for info on venv activation in Jupyter).




回答2:


It apears that you need Numpy 1.17.1(you have Numpy 1.16.0) to use sent2vec

requirements https://github.com/epfml/sent2vec/blob/master/requirements.txt



来源:https://stackoverflow.com/questions/58882055/python-doesnt-see-packages-with-jupyter-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!