Does `pip install` respect the compiler version used to build Python?
Asked Answered
G

3

0

Does pip install always build extension modules with the same compiler that was used to compile the current Python version?

For example, this blog post explained that numpy package uses C code, which has to be compiled against the same compiler as the Python itself:

Python 2.7.13 (default, Aug 21 2017, 11:46:40) [MSC v.1900 64 bit (AMD64)] on win32

tells us which compiler was used. numpy and other packages have to be compiled against that identical version.

Granoff answered 18/3, 2019 at 9:27 Comment(3)
Python is not a compiled language. Are you talking about the interpreter?Vang
It depends on how you have installed pip. While installing pip if you have used python2.7 then pip will install packages corresponding to the said version of pythonIndigence
I added some sample information.Granoff
W
1

pip install never installs a compiler. You have to have the compiler before running pip install.

See https://wiki.python.org/moin/WindowsCompilers to learn what version of VC you need to install for different versions of Python.

It would be much simpler to install a precompiled wheel. Said numpy has a lot of precompiled wheels. Currently there are binary wheels for Python 2.7, 3.5, 3.6 and 3.7 on MacOS 64 bits, Linux 32 and 64 bits, Windows 32 and 64 bits. Just type pip install numpy and your pip automatically determines what platform it's being ran on and download and install the proper wheel.

William answered 18/3, 2019 at 13:14 Comment(0)
S
1

Yes! Originally pip was built on top of distutils package which by default enforces extension modules to be compiled with the same compiler as an interpreter itself. Currently it mostly installs packages from pre-built wheels (which in turn are also built with help of distutils) and packages still have to use setuptools to be able to build extension modules.

On Windows com­piler ver­sion is also enforced to be the same (or, since Python 3.5, compatible). On Unix-likes the compiler and linker flags used to compile Python will also be used to compile extensions.


Note that this is more of a convenience and safeguard rather than a requirement. Except for some special cases Python exten­sions should work just fine when built with another compiler version.

Saw answered 11/12, 2020 at 16:39 Comment(0)
S
0

Pip prioritises the version on your PATH. Pip3 and Pip are used to differentiate between the two versions.

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

Serviceman answered 18/3, 2019 at 9:30 Comment(1)
This doesn't regard the question I askedGranoff

© 2022 - 2024 — McMap. All rights reserved.