Why Do Some Python Libraries Require Compilation During Installation?

Hey,

I’ve noticed that some Python libraries require compilation during installation. Why is this necessary, and are there efforts being made to make Python packages more lightweight to install, without needing a compilation step?

Thanks

It becuase they are written in C or C++ usually.

Either the author did not upload to PyPI the compiled version or only supports older versions of Python. You can check what is available on the PyPI page for the module.

Especially on Windows it is a challenge for many user to get these modules to compile.

You can try contacting the auithor and ask them to build for your OS.

To elaborate a little on Barry’s reply.

PyPI distributions can come in 2 forms, a source distribution (aka an
“sdist”, a .tag.gz file which pip or equivalent download and
“build”) and binary distributions (aka a “wheel”, which is a zip file
with a .whl file extension), which tools like pip simply fetch and
unpack.

If a package has a C component (or C++ or Rust or …) which needs
compiling to machine code then that compilation either has to be done by
the author and a wheel for that platform supplied, or the sdist is
fetched and the wheel is built locally on your system.

There can be many wheels, covering various target platforms (eg “windows
intel 32-bit” and so forth). But if there isn’t one then pip has to
use the sdist and build one.

You can tell pip to prefer wheels if available, or to prefer sdists,
or to use only wheels. See pip help install.