Reputation: 151
I am trying to use a spacy 'en' model in PyCharm
to run this code:
import spacy
nlp= spacy.load('en')
doc=nlp(u'I am trying to learn natural language processing for chatbots')
for token in doc:
print(token.txt,token.pos)
how ever, I tried to do this command in pycharm to run the model:
"/Users/zahraaal-nemer/Desktop/University/Level 9/Graduation Project/Studying Ch2/venv/bin/python" "/Users/zahraaal-nemer/Desktop/University/Level 9/Graduation Project/Studying Ch2/main.py"
Traceback (most recent call last):
File "/Users/zahraaal-nemer/Desktop/University/Level 9/Graduation Project/Studying Ch2/main.py", line 2, in <module>
nlp= spacy.load('en')
File "/Users/zahraaal-nemer/Desktop/University/Level 9/Graduation Project/Studying Ch2/venv/lib/python3.9/site-packages/spacy/__init__.py", line 30, in load
return util.load_model(name, **overrides)
File "/Users/zahraaal-nemer/Desktop/University/Level 9/Graduation Project/Studying Ch2/venv/lib/python3.9/site-packages/spacy/util.py", line 175, in load_model
raise IOError(Errors.E050.format(name=name))
OSError: [E050] Can't find model 'en'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.
Process finished with exit code 1
and I tried to apply this code:
FULL_PATH_TO_PYTHON_INTERPRTER -m spacy download en
as follows:
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3 -m spacy download en
the output of running the python3 -m spacy download en on anaconda terminal:
Last login: Sat Nov 14 07:19:49 on ttys000
. /Users/zahraa-maher/opt/anaconda3/bin/activate && conda activate /Users/zahraa-maher/opt/anaconda3;
(base) zahraa-maher@Zahraas-MacBook-Pro ~ % . /Users/zahraa- maher/opt/anaconda3/bin/activate && conda activate /Users/zahraa- maher/opt/anaconda3;
(base) zahraa-maher@Zahraas-MacBook-Pro ~ % python3 -m spacy download en
Requirement already satisfied: en_core_web_sm==2.3.1 from https://github.com/explosion/spacy- models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz#egg=en_core_web_sm==2.3.1 in ./opt/anaconda3/lib/python3.8/site-packages (2.3.1)
Requirement already satisfied: spacy<2.4.0,>=2.3.0 in ./opt/anaconda3/lib/python3.8/site-packages (from en_core_web_sm==2.3.1) (2.3.2)
Requirement already satisfied: thinc==7.4.1 in ./opt/anaconda3/lib/python3.8/site-packages (from spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (7.4.1)
Requirement already satisfied: wasabi<1.1.0,>=0.4.0 in ./opt/anaconda3/lib/python3.8/site-packages (from spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (0.8.0)
Requirement already satisfied: blis<0.5.0,>=0.4.0 in ./opt/anaconda3/lib/python3.8/site-packages (from spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (0.4.1)
Requirement already satisfied: plac<1.2.0,>=0.9.6 in ./opt/anaconda3/lib/python3.8/site-packages (from spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (1.1.3)
Requirement already satisfied: srsly<1.1.0,>=1.0.2 in ./opt/anaconda3/lib/python3.8/site-packages (from spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (1.0.3)
Requirement already satisfied: requests<3.0.0,>=2.13.0 in ./opt/anaconda3/lib/python3.8/site-packages (from spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (2.24.0)
Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in ./opt/anaconda3/lib/python3.8/site-packages (from spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (1.0.4)
Requirement already satisfied: catalogue<1.1.0,>=0.0.7 in ./opt/anaconda3/lib/python3.8/site-packages (from spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (1.0.0)
Requirement already satisfied: tqdm<5.0.0,>=4.38.0 in ./opt/anaconda3/lib/python3.8/site-packages (from spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (4.47.0)
Requirement already satisfied: numpy>=1.15.0 in ./opt/anaconda3/lib/python3.8/site-packages (from spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (1.18.5)
Requirement already satisfied: cymem<2.1.0,>=2.0.2 in ./opt/anaconda3/lib/python3.8/site-packages (from spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (2.0.4)
Requirement already satisfied: setuptools in ./opt/anaconda3/lib/python3.8/site-packages (from spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (49.2.0.post20200714)
Requirement already satisfied: preshed<3.1.0,>=3.0.2 in ./opt/anaconda3/lib/python3.8/site-packages (from spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./opt/anaconda3/lib/python3.8/site-packages (from requests<3.0.0,>=2.13.0->spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (1.25.9)
Requirement already satisfied: chardet<4,>=3.0.2 in ./opt/anaconda3/lib/python3.8/site-packages (from requests<3.0.0,>=2.13.0->spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in ./opt/anaconda3/lib/python3.8/site-packages (from requests<3.0.0,>=2.13.0->spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (2.10)
Requirement already satisfied: certifi>=2017.4.17 in ./opt/anaconda3/lib/python3.8/site-packages (from requests<3.0.0,>=2.13.0->spacy<2.4.0,>=2.3.0->en_core_web_sm==2.3.1) (2020.6.20)
✔ Download and installation successful
You can now load the model via spacy.load('en_core_web_sm')
✔ Linking successful
/Users/zahraa-maher/opt/anaconda3/lib/python3.8/site- packages/en_core_web_sm -->
/Users/zahraa-maher/opt/anaconda3/lib/python3.8/site- packages/spacy/data/en
You can now load the model via spacy.load('en')
and here is when I run echo ./opt/anaconda3/lib/python3.8:
(base) zahraa-maher@Zahraas-MacBook-Pro ~ % echo ./opt/anaconda3/lib/python3.8
./opt/anaconda3/lib/python3.8
and after I did that, I run this code on py charm: import spacy
import spacy
nlp= spacy.load("en_core_web_sm")
and the output was:
"/Users/zahraa-maher/Desktop/study nlp/nlp codes/bin/python" /Users/zahraa-maher/PycharmProjects/pythonProject/main.py
Traceback (most recent call last):
File "/Users/zahraa-maher/PycharmProjects/pythonProject/main.py", line 2, in <module>
spacynlp= spacy.load("en_core_web_sm")
File "/Users/zahraa-maher/Desktop/study nlp/nlp codes/lib/python3.8/site-packages/spacy/__init__.py", line 30, in load
return util.load_model(name, **overrides)
File "/Users/zahraa-maher/Desktop/study nlp/nlp codes/lib/python3.8/site-packages/spacy/util.py", line 175, in load_model
raise IOError(Errors.E050.format(name=name))
OSError: [E050] Can't find model 'en_core_web_sm'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.
Process finished with exit code 1
which still not works and shows the same error, and I am not sure of the python interpreter path
and I don't know how to get the right one to let it work in pyCharm, I used the one I have shown for you as I found by a method when I researched before, but it does not work
could someone help me to solve this issue and let it work on pyCharm?
I am using Mac OS and it has python 2 installed by default, and I also installed python 3.8 with anaconda
and I want to use the models inside the pycahrm or any IDE but not in Jupyter notebook
Upvotes: 0
Views: 842
Reputation: 16660
After the details added, it seems that you are downloading the model for a base
anaconda environment whereas when you run your code from PyCharm you are using a virtual environment from /Users/zahraa-maher/Desktop/study nlp/nlp codes
directory which has nothing to do with the anaconda one.
I suggest that in PyCharm you run system command line and rerun download of the model:
python3 -m spacy download en
PyCharm is going to ensure you are executing this in the context of proper Python environment.
Upvotes: 1