Install Third Party Packages

A Python package is the collection of Python modules, in which similar modules are grouped a separate directory.

Some packages provide source distributions (sdists) and some provide binary distributions (wheels).

When you install, pip will typically prefer a binary package if it is available.

If a binary package is not available, the source package is installed and built.

You can force using a binary package with the options
  • --prefer-binary (prefer older binary packages over newer source packages)
  • --only-binary <format_control> (fail if binary package not available).

You can force using a source package with the option --no-binary <format_control>.

Building source distributions

The following are the pre-requisites for most Python packages:

  • A C/C++ development environment
  • The required LIB and INCLUDE directories for any dependencies must specified in the environment.
  • Visual Studio. Python will identify the files if the Visual Studio is installed in the default location.

    CIMPLICITY and CIMPLICITY Python are compiled as 32-bit programs. Any dependent binary libraries must be built as 32-bit. The install documentation of the package would include the instructions for building it.

    You will need to update the INCLUDE and LIB environment variables to point to any dependencies before you build. For example:

    C:\> set LIB=C:\OpenSSL-win32\lib;%LIB%
    C:\> set INCLUDE=C:\OpenSSL-win32\include;%INCLUDE%

Refer to the following links for more information:

https://cryptography.io/en/latest/installation/#building-cryptography-on-windows

https://packaging.python.org/guides/installing-scientific-packages/

https://packaging.python.org/guides/installing-scientific-packages/#windows-installers

Example: Installing Pillow package from source

The Pillow package provides image processing capabilities and is available as a binary wheel for most Operating Systems. However, if you wanted to build it from source, you could run the command:
pip3 install --no-binary :all: pillow

If you get an error you can perform the following steps:

  1. Install the zlib and libjpeg libraries using vcpkg (https://github.com/microsoft/vcpkg) using the vcpkg command.
    \vcpkg.exe install --triplet x86-windows zlib ijg-libjpeg
  2. Add the vcpgk include and lib directories to the environment:
    set LIB=%LIB%;V:\vcpkg\installed\x86-windows\lib 
    set INCLUDE=%INCLUDE%;V:\vcpkg\installed\x86-windows\include
  3. Run the pip install command again.
    >>> from PIL import Image 
    >>> im = Image.open('c:\\temp\\fig.png') 
    >>> print(im.format, im.size, im.mode) PNG (640, 480) RGBA 
Refer to the following links for the downloads or more information on installation:

https://pillow.readthedocs.io/

https://pillow.readthedocs.io/en/stable/installation.html#building-from-source

https://github.com/microsoft/vcpkg

Example: Installing matplotlib package from source

The matplotlib package has binary wheels. Hence, you need not build it from source.

If you cannot download freetype-2.6.1.tar.gz from the Online links, you can perform the steps documented at https://matplotlib.org/stable/users/installing/index.html#installing-from-source

  1. Get the repository from git and perform pip install from the local code. You can then download freetype-2.6.1.tar.gz manually and put in the build/ directory.
  2. Run the following python script:
    Note: Python distribution does not include the tkinter package. You cannot use the default backend for matplotlib. Instead, you can use the agg backend that can write to the files instead of displaying it on the screen.
    import matplotlib 
    import matplotlib.pyplot as plt 
    import subprocess 
    matplotlib.use('agg') 
    plt.plot([1, 2, 3, 4], [1, 4, 2, 3]) 
    plt.savefig('c:\\temp\\fig.png', dpi=100) 
    subprocess.run(['cmd.exe', '/c', 'c:\\temp\\fig.png']) 

Unix-only packages

Not all packages are available on Windows.

For example, pip3 install uwsgi gives the following error message:

AttributeError: module 'os' has no attribute 'uname'.

The os.uname() function in available only in unix-based Operating Systems.