使用pip安装Spacy时出现错误

4
我将尝试在我的电脑上安装Spacy,但是当我运行以下命令时出现了问题:
pip.exe install spacy

我遇到了这个错误:
Requirement already satisfied (use --upgrade to upgrade): spacy in c:\python27
Collecting numpy (from spacy)
  Using cached numpy-1.9.2.tar.gz
    Running from numpy source directory.
Collecting murmurhash (from spacy)
  Using cached murmurhash-0.24.tar.gz
    warning: manifest_maker: MANIFEST.in, line 5: 'recursive-include' expects <dir> <pattern1> <pattern2> ...
    warning: manifest_maker: MANIFEST.in, line 6: unknown action '*.py'
    warning: manifest_maker: MANIFEST.in, line 7: unknown action '*.rst'
Collecting cymem>=1.11 (from spacy)
  Using cached cymem-1.11.tar.gz
Collecting preshed (from spacy)
  Using cached preshed-0.37.tar.gz
    zip_safe flag not set; analyzing archive contents...
    headers_workaround.__init__: module references __file__
Installed c:\users\hp-por~1\appdata\local\temp\pip-build-y5elnp\preshed\.eggs\headers_workaround-0.17-py2.7.egg
Collecting thinc (from spacy)
  Using cached thinc-1.75.tar.gz
    zip_safe flag not set; analyzing archive contents...
    headers_workaround.__init__: module references __file__
    Installed c:\users\hp-por~1\appdata\local\temp\pip-build-y5elnp\thinc\.eggs\headers_workaround-0.17-py2.7.egg
Requirement already satisfied (use --upgrade to upgrade): unidecode in c:\python27\lib\site-packages (from spacy)
Requirement already satisfied (use --upgrade to upgrade): wget in c:\python27\lib\site-packages (from spacy)
Requirement already satisfied (use --upgrade to upgrade): plac in c:\python27\lib\site-packages (from spacy)
Requirement already satisfied (use --upgrade to upgrade): six in c:\python27\lib\site-packages (from spacy)
Installing collected packages: thinc, preshed, cymem, murmurhash, numpy
  Running setup.py install for thinc
    building 'thinc.learner' extension
    C:\Users\HP-PORTABLE\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I. -IC:\Python27\include -IC:\Python27\include -IC:\Python27\PC /Tpthinc/learner.cpp /Fobuild\temp.win32-2.7\Release\thinc/learner.obj -O3
    cl : Command line warning D9002 : ignoring unknown option '-O3'
    learner.cpp
    thinc/learner.cpp(238) : fatal error C1083: Cannot open include file: 'stdint.h': No such file or directory
    error: command 'C:\\Users\\HP-PORTABLE\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit status 2
    Complete output from command C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\hp-por~1\\appdata\\local\\temp\\pip-build-y5elnp\\thinc\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\hp-por~1\appdata\local\temp\pip-qxxztl-record\install-record.txt --single-version-externally-managed --compile:
    running install

running build

running build_py

creating build

creating build\lib.win32-2.7

creating build\lib.win32-2.7\thinc

copying thinc\context_fields.py -> build\lib.win32-2.7\thinc

copying thinc\util.py -> build\lib.win32-2.7\thinc

copying thinc\__init__.py -> build\lib.win32-2.7\thinc

copying thinc\cache.pyx -> build\lib.win32-2.7\thinc

copying thinc\cy_svm.pyx -> build\lib.win32-2.7\thinc

copying thinc\features.pyx -> build\lib.win32-2.7\thinc

copying thinc\learner.pyx -> build\lib.win32-2.7\thinc

copying thinc\search.pyx -> build\lib.win32-2.7\thinc

copying thinc\thinc.pyx -> build\lib.win32-2.7\thinc

copying thinc\weights.pyx -> build\lib.win32-2.7\thinc

copying thinc\cache.pxd -> build\lib.win32-2.7\thinc

copying thinc\cy_svm.pxd -> build\lib.win32-2.7\thinc

copying thinc\features.pxd -> build\lib.win32-2.7\thinc

copying thinc\learner.pxd -> build\lib.win32-2.7\thinc

copying thinc\search.pxd -> build\lib.win32-2.7\thinc

copying thinc\thinc.pxd -> build\lib.win32-2.7\thinc

copying thinc\typedefs.pxd -> build\lib.win32-2.7\thinc

copying thinc\weights.pxd -> build\lib.win32-2.7\thinc

copying thinc\__init__.pxd -> build\lib.win32-2.7\thinc

copying thinc\compile_time_constants.pxi -> build\lib.win32-2.7\thinc

running build_ext

building 'thinc.learner' extension

creating build\temp.win32-2.7

creating build\temp.win32-2.7\Release

creating build\temp.win32-2.7\Release\thinc

C:\Users\HP-PORTABLE\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I. -IC:\Python27\include -IC:\Python27\include -IC:\Python27\PC /Tpthinc/learner.cpp /Fobuild\temp.win32-2.7\Release\thinc/learner.obj -O3

cl : Command line warning D9002 : ignoring unknown option '-O3'

learner.cpp

thinc/learner.cpp(238) : fatal error C1083: Cannot open include file: 'stdint.h': No such file or directory

error: command 'C:\\Users\\HP-PORTABLE\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit status 2

----------------------------------------
Command "C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\hp-por~1\\appdata\\local\\temp\\pip-build-y5elnp\\thinc\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\hp-por~1\appdata\local\temp\pip-qxxztl-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\hp-por~1\appdata\local\temp\pip-build-y5elnp\thinc

我已经升级了setuptools,但是没有任何改变。 我正在运行Windows 7 64位操作系统。 我已经安装了适用于Python 2.7的Visual C++编译器包。 我正在尝试在两台不同的电脑上安装,但出现了相同的错误。


尝试安装 python-dev - Heisenberg
谢谢。python-dev似乎只适用于Linux,但我找到了Pythonxy,它可能具有相同的效果。我下载了它(这是一个大文件!)并发布了回复。 - user3310453
https://dev59.com/mGcs5IYBdhLWcg3wSiFo - Padraic Cunningham
相关链接:https://dev59.com/x1cQ5IYBdhLWcg3wEPsK - David C
2个回答

0
在Windows中,我安装pip包时遇到了很多问题。我找到的一个解决方案(我仍在使用)是使用“virtualenv”为我的项目创建虚拟环境。Pip似乎在venv中比C:路线更好地工作。
您可以通过pip安装virtualenv pip install virtualenv或查看安装指南
安装后,只需在项目路径(或任何其他位置)中创建虚拟环境并激活它。打开cmd终端并使用:
> virtualenv name_of_the_enviroment
> name_of_the_enviroment/Scripts/activate
> pip install spacy

我强烈建议将Python路由放在您的环境变量中,这样您可以在cmd终端中使用“pip”,“python”等命令。

现在,当您使用“pip install some_package”时,它将被安装在虚拟环境中。 deactivate 将停用虚拟环境。

注意:请注意,每当您想要使用软件包或使用已安装软件包启动项目时,必须激活虚拟环境。


2
谢谢,但是我在新环境中(名为 myspacy)运行时仍然遇到同样的错误: (myspacy) C:\Python27\Scripts\myspacy\Scripts>pip.exe install spacy。 - user3310453

0

这可能是与您的虚拟环境(venv)中安装的其他Python包发生冲突。这就是我遇到的情况。我尝试在已经安装了这些包的venv中进行pip安装:

appnope==0.1.0
beautifulsoup4==4.5.1
bs4==0.0.1
chardet==2.3.0
cloudpickle==0.2.1
cssselect==1.0.0
cymem==1.31.2
decorator==4.0.10
entrypoints==0.2.2
headers-workaround==0.18
ipykernel==4.5.2
ipython==5.1.0
ipython-genutils==0.1.0
ipywidgets==5.2.2
Jinja2==2.8
jsonschema==2.5.1
jupyter==1.0.0
jupyter-client==4.4.0
jupyter-console==5.0.0
jupyter-core==4.2.1
lxml==3.6.4
MarkupSafe==0.23
mistune==0.7.3
murmurhash==0.26.4
nbconvert==4.2.0
nbformat==4.2.0
notebook==4.2.3
numpy==1.11.2
pandas==0.19.1
pathlib==1.0.1
pdfminer.six==20160614
pdfminer3k==1.3.1
pdfquery==0.4.3
pexpect==4.2.1
pickleshare==0.7.4
plac==0.9.6
ply==3.9
preshed==0.46.4
prompt-toolkit==1.0.9
ptyprocess==0.5.1
py==1.4.31
Pygments==2.1.3
pyquery==1.2.17
pytest==3.0.3
python-dateutil==2.6.0
pytz==2016.7
pyzmq==16.0.2
qtconsole==4.2.1
requests==2.11.1
roman==2.0.0
semver==2.7.2
simplegeneric==0.8.1
six==1.10.0
slate==0.3
sputnik==0.9.3
terminado==0.6
thinc==5.0.8
tornado==4.4.2
traitlets==4.3.1
ujson==1.35
wcwidth==0.1.7
widgetsnbextension==1.2.6

即使升级了setuptools,它仍然失败了。

尝试创建一个全新的环境conda create -n spacy python=3,继续安装默认包(openssl、pip、wheel等),并在激活新的虚拟环境source activate spacy后运行pip install -U spacy。它成功地安装到了虚拟环境中。从那里安装你需要的其他包。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接