1

(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 了!

希望它会帮助别人

4

1 回答 1

0

由于我是 Stackoverflow 的新手,因此我无法评论或将此问题标记为可能的重复问题……<br> 因此,作为“正常”答案:正如答案中提到的,似乎有适用于 Mac OS 的解决方案。希望这可以帮助!

于 2017-02-19T18:59:34.353 回答