SecretIndividual
SecretIndividual

Reputation: 2549

ImportError loading spacy in jupyter notebook

I got a problem I can't seem to figure out. The first time I imported Spacy into a Jupyter notebook I had no problems. It just imported it as I expected.

The second time I tried to import it (using a different notebook) I got:

ImportError: cannot import name 'prefer_gpu' from 'thinc.api' (C:\python-environments\nlp\lib\site-packages\thinc\api.py)

So I tried to restart the kernel and tried it again (thinking that might be the issue). That did not solve it. Also trying to run the same cell that imported Spacy in the first notebook also throws the error now after it went well the first time.

Upvotes: 3

Views: 3956

Answers (2)

vcnr_1234
vcnr_1234

Reputation: 63

I had a similar issue, followed the git hub link, created a new environment, and installed all required packages, and it resolved my issue. I'm using Visual code, so I had to install other dependencies since VC uses this as a conda environment as a base for my code implementation

Upvotes: 0

polm23
polm23

Reputation: 15633

It sounds like you have an old version of Thinc somewhere; try uninstalling and reinstalling Thinc.

Another thing to check is if you're running in the right Python environment. Sometimes Jupyter notebooks pull in a different environment than the one you're expecting in non-obvious ways. There was a thread in spaCy discussions about this recently. You can run this command to check which Python executable is being used in the notebook and make sure it's the one you think it is:

import sys
print(sys.executable)

Upvotes: 1

Related Questions