首页 > 解决方案 > 如何在 Windows 10 上安装 nmslib

问题描述

我正在尝试使用 pip 安装 scispacy,发现 nmslib 的安装引起了问题。互联网上有很多关于如何解决这个问题的帖子,但似乎没有一个对我有用。

我在 Windows 10 笔记本电脑上运行 Python 3.7.4 Pip 版本为 19.2.1

这是日志的错误部分

2019-08-08T18:25:20,901 ERROR: Command errored out with exit status 1: 'c:\users\andre\appdata\local\programs\python\python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\andre\\AppData\\Local\\Temp\\pip-install-y6n2f026\\nmslib\\setup.py'"'"'; __file__='"'"'C:\\Users\\andre\\AppData\\Local\\Temp\\pip-install-y6n2f026\\nmslib\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\andre\AppData\Local\Temp\pip-record-90f_5c93\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.
2019-08-08T18:25:20,902 Exception information:
2019-08-08T18:25:20,902 Traceback (most recent call last):
2019-08-08T18:25:20,902   File "c:\users\andre\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\cli\base_command.py", line 188, in main
2019-08-08T18:25:20,902     status = self.run(options, args)
2019-08-08T18:25:20,902   File "c:\users\andre\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\commands\install.py", line 407, in run
2019-08-08T18:25:20,902     use_user_site=options.use_user_site,
2019-08-08T18:25:20,902   File "c:\users\andre\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\req\__init__.py", line 58, in install_given_reqs
2019-08-08T18:25:20,902     **kwargs
2019-08-08T18:25:20,902   File "c:\users\andre\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\req\req_install.py", line 959, in install
2019-08-08T18:25:20,902     spinner=spinner,
2019-08-08T18:25:20,902   File "c:\users\andre\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\utils\misc.py", line 934, in call_subprocess
2019-08-08T18:25:20,902     raise InstallationError(exc_msg)
2019-08-08T18:25:20,902 pip._internal.exceptions.InstallationError: Command errored out with exit status 1: 'c:\users\andre\appdata\local\programs\python\python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\andre\\AppData\\Local\\Temp\\pip-install-y6n2f026\\nmslib\\setup.py'"'"'; __file__='"'"'C:\\Users\\andre\\AppData\\Local\\Temp\\pip-install-y6n2f026\\nmslib\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\andre\AppData\Local\Temp\pip-record-90f_5c93\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

几周前,我遇到了同样的问题,在我尝试的数百万种方法中,我能够让它工作,但当时我并不完全确定我是如何做到的。我现在在一台新电脑上,问题不会消失。

标签: pip

解决方案


nmslib是一个c++库的 python 包装器。因此,它可能会在少数系统上引起问题。我遇到过同样的问题。

请从这里克隆存储库并手动安装而不是pip安装。

尝试以下方法之一。

  1. 根据此处的评论,nmslib是可选的,仅当您将其用于链接器时才需要。因此您可以从 requirements.txt 中对其进行评论,然后通过手动安装setup.py

    或者

  2. 在您requirements.txt file添加numpy到顶部并通过setup.py文件安装。

虽然上述步骤可能会引发 VC++ 错误,但该scispacy模块将被安装并且您将能够导入它。

我尝试了这两种解决方案,它们对我有用。

注意:另外,从评论中我了解到,如果您已经下载并安装了模型,现在我们可以直接使用spacy和加载scispacy模型。

pip install en_core_sci_sm
import spacy
nlp = spacy.load("en_core_sci_sm")

让我知道哪一个适合你。


推荐阅读