【问题标题】:Does `pip install` respect the compiler version used to build Python?`pip install` 是否尊重用于构建 Python 的编译器版本?
【发布时间】:2019-03-18 09:27:04
【问题描述】:

pip install 是否总是使用用于编译当前 Python 版本的相同编译器构建扩展模块?

例如,this blog post 解释说 numpy 包使用 C 代码,必须针对与 Python 本身相同的编译器进行编译:

Python 2.7.13(默认,2017 年 8 月 21 日,11:46:40)[MSC v.1900 64 位 (AMD64)] 在 win32 上

告诉我们使用了哪个编译器。 numpy 和其他包必须针对相同的版本进行编译。

【问题讨论】:

  • Python 不是编译语言。你说的是口译员吗?
  • 这取决于你是如何安装 pip 的。安装 pip 时,如果你使用过 python2.7,那么 pip 将安装对应于所述 python 版本的包
  • 我添加了一些示例信息。

标签: python pip python-extensions


【解决方案1】:

Pip 优先考虑 PATH 上的版本。 Pip3 和 Pip 用于区分两个版本。

https://docs.python.org/2/installing/index.html

【讨论】:

  • 这不考虑我问的问题
【解决方案2】:

pip install 从不安装编译器。在运行pip install之前你必须有编译器。

请参阅https://wiki.python.org/moin/WindowsCompilers,了解您需要为不同版本的 Python 安装哪个版本的 VC。

安装预编译的轮子会简单得多。说numpy有a lot of precompiled wheels。目前在 MacOS 64 位、Linux 32 和 64 位、Windows 32 和 64 位上有 Python 2.7、3.5、3.6 和 3.7 的二进制轮子。只需输入pip install numpy,您的pip 就会自动确定它在哪个平台上运行并下载并安装正确的轮子。

【讨论】:

    【解决方案3】:

    是的pip 建立在 distutils 包和 by default it enforces 扩展模块之上,以 the same compiler 作为解释器本身进行编译。

    在 Windows 编译器版本也是 enforced to be the same(或者,从 Python 3.5 开始,compatible)。在 Unix-likes 上 the same compiler and linker flags 用于编译 Python will also be used 以编译扩展。


    请注意,这更多的是一种方便和保障,而不是一种要求。 Except for some special cases Python 扩展在使用其他编译器版本构建时应该可以正常工作。

    【讨论】:

      猜你喜欢
      • 2023-03-21
      • 2019-11-20
      • 1970-01-01
      • 1970-01-01
      • 2014-05-06
      • 2016-03-07
      • 1970-01-01
      • 2020-08-08
      • 2016-12-20
      相关资源
      最近更新 更多