[英]Trouble Installing spaCy english model in python 2.7? And upgrading python to 3.5?
I am trying to install the spaCy english model on my mac after installing the program. 安装程序后,我试图在Mac上安装spaCy英文模型。 Right now my machine has python 2.7.
现在我的机器上有python 2.7。 I have installed spaCy in the venv then followed that with "python -m spacy.en.download" to install the model as instructed on the website.
我已经在venv中安装了spaCy,然后按照网站上的指示安装“ python -m spacy.en.download”,以安装该模型。 When I try to do that I get the following in response:
当我尝试这样做时,我得到以下响应:
$ python -m spacy.en.download
Traceback (most recent call last): 追溯(最近一次通话):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/Users/katietemrowsky/Documents/Desktop/machine/.env/lib/python2.7/site-packages/spacy/en/download.py", line 1, in import plac File "/Users/katietemrowsky/Documents/Desktop/machine/.env/lib/python2.7/site-packages/plac.py", line 38, in from plac_tk import TkMonitor File "/Users/katietemrowsky/Documents/Desktop/machine/.env/lib/python2.7/site-packages/plac_tk.py", line 46 print('Process %d killed by CTRL-C' % os.getpid(), file=sys.stderr) ^ SyntaxError: invalid syntax
I then tried to install spaCy and the model on my computer outside of the venv which I would rather not do, but wanted to see if it would work. 然后,我尝试在venv之外的计算机上安装spaCy和模型,但我不想这样做,但想查看它是否可以工作。 Again I got the same error.
我再次遇到相同的错误。
Additionally I am wondering if the issue has something to do with running python 2.7? 另外我想知道问题是否与运行python 2.7有关吗? I upgraded my python on my computer to 3.5 but am not sure how to replace 2.7 with 3.5?
我将计算机上的python升级到3.5,但是不确定如何用3.5替换2.7吗? Right now I can run both on the interpreter using
$ python
or $ python3
. 现在,我可以使用
$ python
或$ python3
在解释器上运行它们。 How can I upgrade everything to 3.5? 如何将所有内容升级到3.5?
Thank you in advance! 先感谢您!
In short: 简而言之:
The latest version of spacy
and plac
doesn't have this issue anymore. 最新版本的
spacy
和plac
不再存在此问题。
Upgrade your spacy
version, it should automatically upgrade plac
too: 升级您的
spacy
版本,它也会自动升级plac
:
pip install -U spacy
In long: 总而言之:
In the latest version of spacy
, the import plac
line is no longer in the spacy.en.download.py
but the plac
library is used in other places 在最新版本的
spacy
, import plac
行不再位于spacy.en.download.py
而是在其他地方使用了plac
库
plac
is an argument parser like the native argparse
or the popular docopt
. plac
是一个参数解析器,例如本机argparse
或流行的docopt
。
File "/Users/katietemrowsky/Documents/Desktop/machine/.env/lib/python2.7/site-packages/plac_tk.py", line 46
print('Process %d killed by CTRL-C' % os.getpid(), file=sys.stderr)
^
SyntaxError: invalid syntax
The error you've occurred above is caused by the difference between the print_function
syntax of Python2 and Python3, ie: 您上面发生的错误是由Python2和Python3的
print_function
语法之间的差异引起的,即:
alvas@ubi:~$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print('foo bar', file=sys.stderr)
File "<stdin>", line 1
print('foo bar', file=sys.stderr)
^
SyntaxError: invalid syntax
>>> exit()
alvas@ubi:~$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print('foo bar', file=sys.stderr)
foo bar
And this was introduced by this commit . 这是由commit引入的。
Since there is the from __future__ import print_function
at https://github.com/micheles/plac/blob/46d8d393fbca8820e5cba5d1da808b65a1c879a3/plac_tk.py#L1 由于存在
from __future__ import print_function
位于https://github.com/micheles/plac/blob/46d8d393fbca8820e5cba5d1da808b65a1c879a3/plac_tk.py#L1
The print_function
should have kicked in and allow the file=
parameters in the print for Python2, eg print_function
应该已经print_function
,并允许在Python2的打印file=
参数,例如
alvas@ubi:~$ python2
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import print_function
>>> import sys
>>> print('foo bar', file=sys.stderr)
foo bar
But the __future__
import from plac
didn't kick in and that remains a mystery to me =( But that's another answer for another question at another time... 但是从
plac
导入的__future__
尚未开始,这对我来说仍然是个谜=(但这是另一个时间另一个问题的另一个答案...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.