Published: December 31, 2019 Last Updated: December 7, 2021

Python Package Installation on Windows

Python Package Installation on Windows

Try a faster way of installing Python packages for Windows. Build your own Python environment 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.

Installation Requirements 

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>

  1. Verify that Python is installed: 

Open a Windows command window and run the following command to check that a suitable Python version is installed: 

python --version

Output should be similar to: 

Python 3.6.6

If Python is not installed, you can download a copy of ActiveState’s Python, ActivePython, for free. 

  1. Verify that Pip is installed: 
pip --version

Output should be similar to pip 19.3.1 from c:\python36\lib\site-packages\pip (python 3.6) 

  1. 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

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:

  1. 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

How ActiveState Can Help

ActiveState provides a unified cross-platform toolchain for modern Python package management. It can replace the complex and hard-to-maintain in-house solutions built from multiple package managers, environment management tools and other solutions. 

By adopting the ActiveState Platform, developers can:

  • Automated building of packages from source, including link C libraries without the need for a local build environment.
  • Automated resolution of dependencies (or suggestions on how to manually resolve conflicts), ensuring that your environment always contains a set of known good dependencies that work together. 
  • Central management of a single source of truth for your environment that can be deployed with a single command to all development and CI/CD environments, ensuring consistent reproducibility. 
  • Automated installation of virtual Python environments on Windows or Linux without requiring prior setup. 
  • The ability to find, fix and automatically rebuild vulnerable environments, thereby enhancing security and dramatically reducing time and effort involved in resolving CVEs. 
  • Visually seeing which versions of which packages are approved for use, thereby taking the guesswork out of development.

Those that prefer to work from the command line can leverage the ActiveState Platform’s CLI, the State Tool, which acts as a universal package manager for Python, and provides access to most of the features offered by the Platform.

Python Package management

 

 

 

 

 

 

 

 

 

 

Modern Python Package Management

ActiveState provides a unified cross-platform toolchain for modern Python package management. It can replace the complex and hard-to-maintain in-house solutions built from multiple package managers, environment management tools and other solutions. 

By adopting the ActiveState Platform, developers can: 

  • Increase the security of Python environments
  • Improve the transparency of your open source supply chain
  • Dramatically reduce package and environment management overhead
  • Eliminate dependency hell
  • Reduce “works on my machine” issues

Ultimately, developers that are willing to adopt the ActiveState Platform will spend less time wrestling with tooling and more time focused on doing what they do best: coding.

To try the ActiveState Platform for yourself, sign-up for a free account.

Recommended Reads

How to Manually Install Python Packages

Data Sheet: ActiveState Platform’s Hosted Artifact Repository

Frequently Asked Questions

If necessary, you can manually install Python packages on Windows. 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.

Learn how to install pip on Windows.

You can install Python packages on Windows 10 as long as you have a copy of Python installed. The easiest way to install packages is to use Python’s package manager pip. Just run the following at a command prompt:
pip install <packagename>

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

To learn more about pip, refer to How to Install Pip on Windows.

Python packages on Windows are typically installed either globally (system-wide) or else locally (typically in a virtual environment):

  • Globally installed Python packages can be found under \Program Files\
  • Locally installed Python packages can only be used by the user that installed them. Therefore, they can be found under
    \Users\<Username>\AppData\Local\Programs\

For more information, refer to How To List Globally vs Locally Installed Python Packages.

First, ensure you have Python installed. You can then install the package you want to work with by running the following at a command prompt:
pip install <packagename>

Where packagename is the name of the package to be installed. Finally, you can import the package into your program by typing:
import <packagename>

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

Read more about understanding Python packages.

Katie Chang