How to Manually Install Python Packages

How to Manually Install Python Packages

With deep roots in open source, and as a founding member of the Python Foundation, ActiveState actively contributes to the Python community. We offer the convenience, security and support that your enterprise needs while being compatible with the open source distribution of Python.

Download ActiveState Python to get started or contact us to learn more about using ActiveState Python in your organization.

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:

  1. Download the package and extract it into a local directory.
  2. 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: 

  1. cd into the root directory where setup.py is located 
  2. 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.

Examples

  • 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

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="<authorname@templatepackage.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',

)

Frequently Asked Questions

If necessary, you can manually install packages in Python. Some packages have special installation requirements. Other packages can be installed manually with setup.py. To manually install packages in Python with setup.py, do the following:

  1. Download the package and extract it into a local directory.
  2. Navigate to the directory in which you’ve extracted the package.
  3. If the package includes its own set of installation instructions, they should be followed. Otherwise, use setup.py by running the following command: python setup.py install

You may still need the setuptools library to complete the package build requirements.

See how to install pip on Windows.

The most common way to install Python packages is using Python’s package manager, pip. To install a package using pip, run the following command:
pip install <packagename>

Where packagename is the name of the package to be uninstalled.

Learn more about installing Python packages with pip.

Pip is installed by default with most Python distributions, but if it is not installed on your local system you can manually install pip by either:

Installing a Python distribution like ActivePython, which includes pip, or manually installing pip with get-pip.py: Download get-pip.py. Navigate to the directory where you installed get-pip.py. Run the following command:
python get-pip.py

Learn more about installing pip.

IDLE is Python’s Integrated Development and Learning Environment designed to make learning Python easier. To install Python IDLE packages, you can just use pip by running the following command:
pip install <packagename>

Where packagename is the name of the package to be installed.

How to install Python packages using pip.

Katie Chang