Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'No module named spacy' in ipython, but works fine in regular python interpretter

I am currently trying to import spacy using Jupyter Notebooks and running into a problem. Every time I try to import it, it says that it cannot find the module, even though the regular python shell interpreter works just fine.

Information:

  • Conda Environment

  • installed using conda install -c conda-forge spacy

  • shows up in conda list | grep spacy

  • Jupyter can find other packages in the conda env, just not spacy

Thank you for any help you can provide.

EDIT: Terminal Commands:

1. cd into project directory 2. conda create -n <env name> 3. source activate <env name> 4. conda install -c conda-forge spacy 5. python -m spacy download en 6. python - import spacy #works! - nlp = spacy.load('en') #works! - quit() 7. ipython - import spacy ModuleNotFoundError: No module named 'spacy'

EDIT2: Figured it out. My sys.path was different in ipython and wasn't searching through the conda env. I had to run conda install jupyter in the env and then everything worked. Apparently the root jupyter doesn't detect if you're inside an environment or not.

like image 392
netu Avatar asked Apr 20 '18 04:04

netu


2 Answers

Figured it out. My sys.path was different in ipython v python shell. ipython wasn't searching through the conda env.

I had to run conda install jupyter in the env and then everything worked. Apparently the root jupyter doesn't detect if you're inside an environment or not. This makes sense now that I know some more about the internals as it needs to identify with a specific ipykernel.

Hope this helps anyone else running into the same issue.

like image 54
netu Avatar answered Sep 24 '22 20:09

netu


  • create virtualenv

  • activate it

  • install jupyter and spacy on virtualenv

pip install jupyter     
pip install spacy
  • add kernel
pip install ipykernel
python -m ipykernel install --user --name=newkernelinvenv

start jupyter and load your new kernel

like image 25
jarh1992 Avatar answered Sep 23 '22 20:09

jarh1992