How to install Python package from source on Windows

Gregory Ewing greg.ewing at canterbury.ac.nz
Mon May 15 19:54:49 EDT 2017


Deborah Swanson wrote:
> It continues to amaze me that Anaconda and Python.org, probably the two
> biggest distributors of official Python builds, are now relying on
> Visual C++. Why can't Python developers write the entire setup and
> installation code in Python?

The setup and installation code *is* written in Python. It's
just that some of the source of the particular package you're
trying to install is written in C, so installing it *from
source* necessarily requires a C compiler.

Most people's Windows machines aren't set up for compiling C
code, and for that reason, prebuilt versions of such packages
are usually supplied for Windows.

So you have two reasonable options:

1) Find a prebuilt wheel that's compatible with your system.

2) Find another package written in pure Python that does what
you want.

It's also possible that you don't need the parts of recordclass
that are written in C. If that's the case you might be able to
install the pure Python parts manually. That's usually just a
matter of dropping the .py files in appropriate places.

> Relatedly, why is Python lacking in the basic build tools for users to
> easily build and install packages and full releases from source?
> Something for Python (loosely) akin to the earliest versions of Visual
> Studio would do the job,

Having the Python ecosystem stuck on some ancient version of
Visual Studio would be a bad situation for many reasons. One
of the main uses of C extensions is to interface with external
libraries, which will most likely have been compiled with a
recent toolset and rely on recent versions of Microsoft's
runtime libraries.

There's also the fact that Microsoft doesn't make the free
versions of Visual Studio available forever and forbids anyone
else distributing them, so sufficiently old versions are
simply not available to most people.

The alternative would be to use some other free compiler such
as MinGW as the standard compiler for Python and its extensions.
But this has been decided against on the grounds that it is
better to use the standard Windows tools to compile code for
Windows, for the same compatibility reasons as above, and that
means Visual Studio.

> Ah, and you've got me there. I have no clue what an ABI tag is or why
> it's significant,

ABI = Application Binary Interface. Essentially it's the
interface between the Python interpreter and code that's
been compiled from C, and it can change from one version
of Python to another.

The error message from pip could be more useful -- it would be
nice to know exactly *what* it is about the wheel that doesn't
match your system!

Some things it could be:

* Wrong version of Python

* Wrong CPU architecture (32 vs 64 bit)

-- 
Greg



More information about the Python-list mailing list