Ananth Ravi Kumar
Ananth Ravi Kumar

Reputation: 41

Setting Clang as default compiler used in pip install on Windows

Visual Studio 2017 now ships with clang, and I was wondering if it is possible to set clang to be the default compiler used when trying to install a python package with Cython dependencies via pip install.

As far as I can tell the issue seems to be that pip doesn't know where to look for clang; it defaults to the path containing the MSVC compiler to compile the .c files specified in the package setup.py. Is there any way I can either 1) set the path to the compiler to be used, or 2) specify that clang should be used explicitly?

I'm working on Windows 10, using the Anaconda distribution and Python 3.6. Any help would be much appreciated!

Upvotes: 2

Views: 4542

Answers (1)

danny
danny

Reputation: 5270

Do not do it.

It can be done on the command line by setting compiler:

python setup.py build_ext -c <compiler>

python setup.py build_ext --help-compiler to see available options.

However, the same compiler used to build the python distribution must be used for all extensions as the extension modules will be loaded by the interpreter.

If they are built by a different compiler, they cannot be safely loaded by the python interpreter.

In the case of Anaconda, its python distribution is built with MSVC, so the same compiler used by the anaconda environment should be used for extensions. In that case, activating the anaconda environment should suffice, though compiler can be set explicitly as above.

See Windows Compilers python wiki entry.

Upvotes: 4

Related Questions