无法在python 2.7中安装spaCy英文模型?并将python升级到3.5? [英] Trouble Installing spaCy english model in python 2.7? And upgrading python to 3.5?

查看:379
本文介绍了无法在python 2.7中安装spaCy英文模型?并将python升级到3.5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安装程序后,我试图在Mac上安装spaCy英文模型.现在,我的机器上安装了python 2.7.我已经在venv中安装了spaCy,然后按照网站上的指示安装"python -m spacy.en.download",以安装该模型.当我尝试这样做时,我得到以下响应:

$ python -m spacy.en.download

回溯(最近通话最近一次):

  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

然后,我尝试在venv之外的计算机上安装spaCy和模型,但我不想这样做,但想查看它是否可以工作.我又遇到了同样的错误.

我还想知道问题是否与运行python 2.7有关?我将计算机上的python升级到3.5,但是不确定如何用3.5替换2.7吗?现在,我可以使用$ python$ python3在解释器上运行它们.如何将所有内容升级到3.5?

提前谢谢!

解决方案

简而言之:

spacyplac的最新版本不再存在此问题.

升级您的spacy版本,它也会自动升级plac:

pip install -U spacy

冗长:

在最新版本的spacy中,import plac行不再位于 plac库在其他地方使用

plac 是一个参数解析器,例如本机

您上面发生的错误是由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

这是由 引入的. >

因为在from __future__ import print_function" rel ="nofollow noreferrer"> https://github .com/micheles/plac/blob/46d8d393fbca8820e5cba5d1da808b65a1c879a3/plac_tk.py#L1

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

但是从plac导入的__future__并没有起作用,这对我来说仍然是个谜=(但这是另一个时间另一个问题的另一个答案...

I am trying to install the spaCy english model on my mac after installing the program. Right now my machine has 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. 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. Again I got the same error.

Additionally I am wondering if the issue has something to do with running 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? Right now I can run both on the interpreter using $ python or $ python3. How can I upgrade everything to 3.5?

Thank you in advance!

解决方案

In short:

The latest version of spacy and plac doesn't have this issue anymore.

Upgrade your spacy version, it should automatically upgrade plac too:

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

plac is an argument parser like the native argparse or the popular 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, i.e.:

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.

Since there is the from __future__ import print_function at 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, e.g.

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...

这篇关于无法在python 2.7中安装spaCy英文模型?并将python升级到3.5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆