python安装怎么是英文,无法在python 2.7中安装spaCy英文模型?并将python升级到3.5?...

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装spacy Python库,您可以按照以下步骤进行操作: 1. 首先,确保您的操作系统满足spacy的要求。spacy支持macOS / OS X,Linux和Windows操作系统。对于Windows用户,您可以使用Cygwin、MinGW或Visual Studio来安装spacy。 2. 确保您的Python版本符合要求。spacy要求使用Python 3.6或更高版本,并且只支持64位系统。 3. 使用软件包管理器安装spacyspacy-transformers。您可以使用pip或conda来安装这些库。如果您使用pip,可以运行以下命令来安装spacy: ``` pip install spacy ``` 如果您使用conda,可以运行以下命令来安装spacy: ``` conda install spacy -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ ``` 还可以使用pip来更新pip、setuptools和wheel,以确保它们是最新版本: ``` pip install -U pip setuptools wheel ``` 这样就完成了spacy库的安装。 请注意,根据您的操作系统和Python环境,可能会有一些特定的安装步骤或要求。因此,建议您查阅spacy的官方文档或相关资源,以获取更详细的安装说明和指导。 #### 引用[.reference_title] - *1* [Py之spacyspacy/spacy-transformers 的简介、安装、使用方法之详细攻略](https://blog.csdn.net/qq_41185868/article/details/130652994)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [无法python 2.7安装spaCy英文模型?并将python升级3.5?](https://blog.csdn.net/weixin_28929351/article/details/118790846)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值