Python Package Installation on Windows
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 for free on the ActiveState Platform.
The Pip Package Manager is the de facto standard for managing Python distributions, and is recommended for installing Python packages for Windows.
Pip is installed automatically with Python 2 (>=2.7.9) and Python 3 (>=3.4) installations. The pip command has options for installing, upgrading and deleting packages, and can be run from the Windows command line. By default, pip installs packages located in the Python Package Index (PyPI), but can also install from other indexes. For more information on how to use pip, see the Pip Package Installation instructions below.
Wheels and Windows
Python packages installed with pip on Windows are typically bundled into ‘wheels’ prior to installation. A wheel is a zip-style archive that contains all the files necessary for a typical package installation. Wheels have a .whl extension, and provide a simpler installation than ‘non-wheel’ packages.
Depending on the operating system that a package was built for and built on, the resulting wheel may not include file requirements for Windows. Appveyor offers a hosted continuous integration service that developers can use to package Python code for Windows deployments. Wheels built with Appveyor incorporate Windows support by default, and are usually recognizable by their name, e.g. packagename-2.8-cp37-cp37m-win_amd64.whl.
Before packages can be installed, ensure that your existing Python installation meets the requirements. Requirements will differ depending on whether you installed Python into a virtual environment using venv or virtualenv:
- Venv automatically installs pip into Python 3.4+ virtual environments
- Virtualenv automatically installs pip and wheel into Python 2.7+ and Python 3.3+ virtual environments
Note: If you’re using some form of enhanced shell such as IPython, then prefix the command with the ! character, e.g. !pip install <packagename>
- Verify that Python is installed:
Open a Windows command window and run the following command to check that a suitable Python version is installed:
Output should be similar to:
If Python is not installed, you can download a copy of ActiveState’s Python, ActivePython, for free.
- Verify that Pip is installed:
Output should be similar to pip 19.3.1 from c:\python36\lib\site-packages\pip (python 3.6)
- Update Pip and Wheel to ensure you have the latest version installed:
pip install --upgrade pip wheel
Pip Package Installation
To install a package:
pip install <packagename>
To install a package from a repository other than PyPI, for instance, Github:
pip install -e git+<https://github.com/myrepo.git#egg=packagename>
To upgrade a package that is already installed:
pip install --upgrade <packagename>
To uninstall a package:
pip uninstall <packagename>
To show help for pip, including complete command usage and options:
pip -h pip --help
Pipenv is a new tool for managing dependencies. It uses pip and virtualenv under the hood, and simplifies their usage with a single command line syntax. Like venv, pipenv automatically creates a separate virtual environment for each project.
To install, upgrade or uninstall packages within pipenv, just replace the pip command with pipenv. For example, the following command installs a named package from PyPI:
pipenv install <packagename>
You can also install packages from locations other than PyPI. For example, the following command installs the requests package from a Github repository:
pipenv install -e git+https://github.com/requests/requests.git#egg=requests
Manual Package Installation
Most Python packages are now designed to be compatible with pip. If you have a package that’s not compatible, then you’ll need to do a manual installation.
How to manually install a Python package:
- Download the package and extract it into a local directory.
2a. If the package came with its own set of installation instructions, they should be followed.
2b. If not, then open a command window and cd into the directory, and enter:
python setup.py install