【问题标题】:Installing Python package from source using Microsoft Visual Build Tools 2017使用 Microsoft Visual Build Tools 2017 从源代码安装 Python 包
【发布时间】:2018-03-26 18:25:25
【问题描述】:

我有一个 python 包由于依赖于 Windows 构建工具而无法安装。

我尝试过的事情:

  1. 安装最新版本的 Visual Studio 2017(AFAIK 它应该包含 Microsoft Visual C++ 14.0)。

  2. 直接从此处https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017 安装适用于 Visual Studio 2017 的构建工具。

  3. 明确地将C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools放在我的路径上。

  4. 卸载所有 Visual Studio 并重试。

到目前为止还没有运气。我尝试重新启动终端,重新启动计算机等...我正在使用 GitBash,这可能是相关的,尽管它不会给我带来任何问题。

当我安装这些工具时,我确保检查了“Visual C++ 构建工具”工作流,该工作流选择了“单个组件”选项卡下可用的许多行项目的一部分。

在下面的示例中,我正在安装一个语言模型,但我相信我的问题比这更普遍。我发现很难理解许多组件中的哪些与我的任务相关。我想知道的是:如何验证我是否正确配置了构建工具并且我有正确的版本?任何建议或指导将不胜感激。

错误:

$ pip36 install https://github.com/kpu/kenlm/archive/master.zip
Collecting https://github.com/kpu/kenlm/archive/master.zip
  Downloading https://github.com/kpu/kenlm/archive/master.zip (526kB)
Installing collected packages: kenlm
  Running setup.py install for kenlm: started
    Running setup.py install for kenlm: finished with status 'error'
    Complete output from command c:\users\ks99999999\appdata\local\programs\python\python36-32\python.exe  -u -c "import setuptools, tokenize;__file__='C:\\Users\\ks99999999\\AppData\\Local\\Temp\\pip-tfn5ym94-b uild\\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\ks99999999\AppData\Local\Temp\pip-r2e ogfmd-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'kenlm' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http: //landinghub.visualstudio.com/visual-cpp-build-tools

    ----------------------------------------
Command "c:\users\ks99999999\appdata\local\programs\python\python36-32\python.exe -u -c "import setuptool s, tokenize;__file__='C:\\Users\\ks99999999\\AppData\\Local\\Temp\\pip-tfn5ym94-build\\setup.py';f=getatt r(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __ file__, 'exec'))" install --record C:\Users\ks99999999\AppData\Local\Temp\pip-r2eogfmd-record\install-rec ord.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\ks99999999\Ap pData\Local\Temp\pip-tfn5ym94-build\

【问题讨论】:

  • 您是否已将其添加到您的 Windows PATH 或您的 bash 路径中?
  • 你使用的是什么版本的setuptools
  • 安装后是否尝试过重启?另外,你确定安装构建工具后错误是一样的吗?
  • 另外,Visual C++ 14 在 VS 15 中,而不是在 VS 17 中。由于明确要求 14.0,我有一些实例不能与 VS 17 一起使用; This link worked for me
  • @Priansh 我在高级设置下将它添加到我的 PATH 环境变量中。

标签: python windows build-tools kenlm


【解决方案1】:

Microsoft Visual Studio 不随任何 VC 编译器(或通常的任何编译器)一起提供开箱即用的服务。您的安装是模块化的,因此您必须确保您确实安装了 Visual c++ 与您的 VS2017 安装。此外,IIRC、VS2017 附带 Microsoft Visual C++ 15.0。 You can install the 14.0 compiler with the Standalone Microsoft Visual Studio 2015 build tools。确保您也有正确的 setuptools 版本。

您可以通过查看开始菜单 -> 添加/删除程序并检查已安装程序列表来检查安装了哪个版本的 MSVC。

【讨论】:

  • 我使用的是 Windows 10,所以没有开始菜单。我检查了设置,我可以看到2017版本的Visual Studio,仍然不确定如何直接检查Visual C++版本...
  • 在最初设置构建工具时,我似乎没有选择正确的选项子集。我做到了,现在我已经过了这一步。
猜你喜欢
  • 2018-03-22
  • 1970-01-01
  • 2019-12-27
  • 2021-08-11
  • 1970-01-01
  • 1970-01-01
  • 2018-01-02
  • 2020-05-15
  • 2013-06-04
相关资源
最近更新 更多