How do I install Python packages on Windows?

Question:

I’m having a hard time setting up python packages. EasyInstall from SetupTools is supposed to help that, but they don’t have an executable for Python 2.6.

For instance to install Mechanize, I’m just supposed to put the Mechanize folder in C:Python24Libsite-packages according to INSTALL.txt, but runnning the tests does not work. Can someone help shed some light on this? Thanks!

Asked By: echoblaze

||

Answers:

You don’t need the executable for setuptools.
You can download the source code, unpack it, traverse to the downloaded directory and run python setup.py install in the command prompt

Answered By: Lennart Regebro

This is a good tutorial on how to get easy_install on windows. The short answer: add C:Python26Scripts (or whatever python you have installed) to your PATH.

Answered By: goldenratio

You can also just download and run ez_setup.py, though the SetupTools documentation no longer suggests this. Worked fine for me as recently as 2 weeks ago.

Answered By: Kevin Horn

As I wrote elsewhere

Packaging in Python is dire. The root cause is that the language ships without a package manager.

Fortunately, there is one package manager for Python, called Pip. Pip is inspired by Ruby’s Gem, but lacks some features. Ironically, Pip itself is complicated to install. Installation on the popular 64-bit Windows demands building and installing two packages from source. This is a big ask for anyone new to programming.


So the right thing to do is to install pip. However if you can’t be bothered, Christoph Gohlke provides binaries for popular Python packages for all Windows platforms http://www.lfd.uci.edu/~gohlke/pythonlibs/

In fact, building some Python packages requires a C compiler (eg. mingw32) and library headers for the dependencies. This can be a nightmare on Windows, so remember the name Christoph Gohlke.

Answered By: Colonel Panic

The accepted answer is outdated. So first, pip is preferred over easy_install, (Why use pip over easy_install?). Then follow these steps to install pip on Windows, it’s quite easy.

  1. Install setuptools:

    curl https://bootstrap.pypa.io/ez_setup.py | python
    
  2. Install pip:

    curl https://bootstrap.pypa.io/get-pip.py | python
    
  3. Optionally, you can add the path to your environment so that you can use pip anywhere. It’s somewhere like C:Python33Scripts.

Answered By: h–n

I had problems in installing packages on Windows. Found the solution. It works in Windows7+. Mainly anything with Windows Powershell should be able to make it work. This can help you get started with it.

  • Firstly, you’ll need to add python installation to your PATH variable. This should help.
  • You need to download the package in zip format that you are trying to install and unzip it. If it is some odd zip format use 7Zip and it should be extracted.
  • Navigate to the directory extracted with setup.py using Windows Powershell (Use link for it if you have problems)
  • Run the command python setup.py install

That worked for me when nothing else was making any sense. I use Python 2.7 but the documentation suggests that same would work for Python 3.x also.

Answered By: Aseem Bansal

Newer versions of Python for Windows come with the pip package manager. (source)

pip is already installed if you’re using Python 2 >=2.7.9 or Python 3 >=3.4

Use that to install packages:

cd C:PythonScripts
pip.exe install <package-name>

So in your case it’d be:

pip.exe install mechanize
Answered By: Leif Gruenwoldt

Starting with Python 2.7, pip is included by default. Simply download your desired package via

python -m pip install [package-name]
Answered By: phil294
PS D:simcut>  C:Python27Scriptspip.exe install networkx
Collecting networkx
c:python27libsite-packagespip_vendorrequestspackagesurllib3utilssl_.py:318: SNIMissingWarning: An HTTPS reques
t has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may caus
e the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer ve
rsion of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissi
ngwarning.
  SNIMissingWarning
c:python27libsite-packagespip_vendorrequestspackagesurllib3utilssl_.py:122: InsecurePlatformWarning: A true SS
LContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL con
nections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.
readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading networkx-1.11-py2.py3-none-any.whl (1.3MB)
    100% |################################| 1.3MB 664kB/s
Collecting decorator>=3.4.0 (from networkx)
  Downloading decorator-4.0.11-py2.py3-none-any.whl
Installing collected packages: decorator, networkx
Successfully installed decorator-4.0.11 networkx-1.11
c:python27libsite-packagespip_vendorrequestspackagesurllib3utilssl_.py:122: InsecurePlatformWarning: A true SSLContext object i
s not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade
to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplat
formwarning.
  InsecurePlatformWarning

Or just put the directory to your pip executable in your system path.

Answered By: Mona Jalal

As mentioned by Blauhirn after 2.7 pip is preinstalled. If it is not working for you it might need to be added to path.

However if you run Windows 10 you no longer have to open a terminal to install a module. The same goes for opening Python as well.

You can type directly into the search menu pip install mechanize, select command and it will install:

enter image description here

If anything goes wrong however it may close before you can read the error but still it’s a useful shortcut.

Answered By: Xantium

pip is the package installer for python, update it first, then download what you need

python -m pip install --upgrade pip

Then:

python -m pip install <package_name>
Answered By: PodTech.io

Upgrade the pip via command prompt ( Python Directory )

D:Python 3.7.2>python -m pip install --upgrade pip

Now you can install the required Module

D:Python 3.7.2>python -m pip install <<yourModuleName>>
Answered By: Lova Chittumuri
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.