在Spacy for Python3中安装英文模型的问题

时间:2017-01-25 11:34:44

标签: python python-3.6 spacy

(Mac os X 10.12.2)

所以,当我运行这两行时:

pip install spacy
python -m spacy.en.download all

它工作得很好,我可以在python(2.x)中使用spacy和英文模型

但是当我为python3(3.6.0)运行相同的时候

pip3 install spacy
python3 -m spacy.en.download all

它安装了spacy,但下载模型时出错了。所以,当我在python3中使用spacy时,它不起作用,我得到空字段而不是pos,tag ...

我得到的错误与urllib相关:

Downloading parsing model
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect
server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 401, in wrap_socket
_context=self, _session=session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 808, in __init__
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1061, in do_handshake
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/spacy/en/download.py", line 25, in <module>
plac.call(main)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plac_core.py", line 328, in call
cmd, result = parser.consume(arglist)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plac_core.py", line 207, in consume
return cmd, self.func(*(args + varargs + extraopts), **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/spacy/en/download.py", line 18, in main
download('en', force=False, data_path=data_path)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/spacy/download.py", line 36, in download
about.__models__.get(lang, lang), data_path)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sputnik/__init__.py", line 37, in install
index.update()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sputnik/index.py", line 84, in update
index = json.load(session.open(request, 'utf8'))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sputnik/session.py", line 43, in open
r = self.opener.open(request)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>

关于该怎么做的任何想法?

非常感谢! 欢呼声

编辑:我已经在Github上的spacy存储库中提出了问题,显然唯一的方法是将数据从python2.7复制/粘贴到python3.6:

所以我复制/粘贴文件夹en-1.1.0 来自/Users/[myname]/anaconda/lib/python2.7/site-packages/spacy/data/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/spacy/data/

一切正常,现在可以在python3中使用Spacy!

希望它会帮助别人

1 个答案:

答案 0 :(得分:0)

由于我是Stackoverflow的新手,我无法将此问题评论或标记为可能的重复...
所以作为一个正常的&#34;回答:如this中所述,答案似乎是Mac OS的解决方案。希望这有帮助!