How to Manually Install Python Packages
Most Python packages are now designed to be compatible with Python’s pip package manager. But if you have a package that is not compatible with pip, you’ll need manually install Python packages. Here’s how.
Python Installation Checklist
Before installing any package, you should always ensure that a Python installation containing the necessary files needed for installing packages is in place by following the Installation Requirements.
Packages That Cannot be Installed with Pip
Preliminary Steps to take:
- Download the package and extract it into a local directory.
- If the package includes its own set of installation instructions, they should be followed. Otherwise, the most common method for manually installing a package is to implement setup.py.
Installing Python Packages with Setup.py
To install a package that includes a setup.py file, open a command or terminal window and:
- cd into the root directory where setup.py is located
- Enter: python setup.py install
Setup.py Build Environment
Packages installed with setup.py have build requirements that developers must adhere to. However, some requirements are optional.
- Ensure that an up-to-date version of setuptools is installed:
python -m pip install --upgrade setuptools
- Include install_requires keyword arguments in setup.py. install_requires is a setuptools setup.py keyword used to specify minimum package requirements. For example:
install_requires=['<packagename>'], # Optional keyword
Complete package build requirements for a setup.py based installation are outlined by PyPA (Python Packaging Authority) in ‘Sample Project’.
Sample Project is a template package with a setup.py file for manual installation of a package. The file is annotated with comments for customizing the script, and for the overall package build environment. [https://github.com/pypa/sampleproject ]
Sample Project is based on the setuptools package: “A setuptools based setup module.” https://github.com/pypa/sampleproject/blob/master/setup.py ]
setup.py is the build script for packages built with setuptools.
Setup.py Example (Non-Annotated)
import setuptools with open("README.md", "r") as fh: long_description = fh.read() setuptools.setup( name="<template-package-username>", # Replace with your username version="1.0.0", author="<authorname>", author_email="<email@example.com>", description="<Template Setup.py package>", long_description=long_description, long_description_content_type="text/markdown", url="<https://github.com/authorname/templatepackage>", packages=setuptools.find_packages(), classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ], python_requires='>=3.6', )
Try a faster way of installing Python packages for Windows. Get ActivePython or build your own Python runtime with the packages you need. Get started free on the ActiveState Platform.