Can‘t find model ‘en‘ConnectionError: HTTPSConnectionPool(host=‘raw.githubusercontent.com‘, port=443

pip install spacy  和 pip install torchtext 后python语句 en = spacy.load('en') 运行报错如下:

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.

解决命令如下:

python -m spacy download en

类似的有  python -m spacy download fr ,python -m spacy download de 等

然而运行  python -m spacy download en  命令,报错如下:

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='raw.githubusercontent.com', port=443): Max retries exceeded with url: /explosion/spacy-models/master/shortcuts-v2.json (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused'))
网络问题,可以试试换一个网络,我在另外一台服务器上运行 python -m spacy download en可成功,

于是可尝试收到下载安装包手动pip安装,

每个模型的下载地址大约相同,支持的语言列表,可以看这里:https://github.com/explosion/spacy-models/releases/,例如下载2.2.5版本的,可以浏览器直接打开下载,也可以通过wget命令下载,

https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.2.5/en_core_web_sm-2.2.5.tar.gz

https://github.com/explosion/spacy-models/releases/download/de_core_news_sm-2.2.5/de_core_news_sm-2.2.5.tar.gz https://github.com/explosion/spacy-models/releases/download/fr_core_news_sm-2.2.5/fr_core_news_sm-2.2.5.tar.gz

cd 进入文件所在的文件夹下手动pip install,例如:

pip install fr_core_news_sm-2.2.5.tar.gz

安装完成后,程序en = spacy.load('en')依然会报错,我找到的方法如下:

一般pip安装完成后安装的库会在所在环境的site-packages文件夹内,例如:

./anaconda3/envs/pytorch/lib/python3.7/site-packages或者./PycharmProjects/First_Project/venv/lib/python3.6/site-packages

也可以通过locate查找安装的位置 如locate de_core_news_sm

将your_path/site-packages/fr_core_news_sm/fr_core_news_sm-2.2.5/ 复制到程序所在的目录下,类似的fr = spacy.load('fr')即可运行通过,例如 cp -r ./anaconda3/envs/pytorch/lib/python3.7/site-packages/fr_core_news_sm/fr_core_news_sm-2.2.5/ ./PycharmProjects/First_Project/, 并将fr_core_news_sm-2.2.5 改名为fr

当然如果一开始能直接运行 python -m spacy download fr成功就直接可以运行fr = spacy.load('fr'),如果有小可爱找到更好的方法,欢迎留言。

你可能感兴趣的:(软件应用,深度学习,数据挖掘,github)