145

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:\Python24\Lib\site-packages according to INSTALL.txt, but runnning the tests does not work. Can someone help shed some light on this? Thanks!

CCovey
  • 799
  • 1
  • 10
  • 17
echoblaze
  • 11,176
  • 13
  • 44
  • 49
  • 5
    As of March, 2014, the [pip package manager is included with Python 3.4 on all platforms, including Windows](https://docs.python.org/3/whatsnew/3.4.html#whatsnew-pep-453). So ensuring you are running Python 3.4 might be a good option. – dodgy_coder Jun 03 '14 at 07:01
  • install python 2.7.10 or 3.4 above which has by default pip in it.Then use python -m pip install Django in cmd and so on – Saurabh Nov 30 '15 at 08:20

12 Answers12

158

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:\Python33\Scripts.

Community
  • 1
  • 1
h--n
  • 5,903
  • 4
  • 31
  • 32
  • 7
    of all the suggestions, this is the only one that worked for me. My environment - Python 3.3.1 , Windows 7 64bit, x64 PC. if possible, please upvote this, saves ppl a lot of trouble. – Quest Monger May 10 '13 at 01:54
  • 7
    the above worked for me, but the second curl with https gave a warning about the ssl certificate expired. had to use --insecure on the curl command line – Anton Jun 24 '13 at 13:37
  • 1
    1st Answer is still valid, though PIP is superior IMO – David Barker Oct 08 '13 at 13:46
  • @h--n Thanks to you, I've now got a working script that reads my Amazon doc list. Prior to this, I never touched Python! :) So thank you :). – Richard Griffiths Jan 05 '14 at 14:44
  • 4
    The above worked for me (Windows7 x64, python 2.7) but to install pip I had to follow the instructions @ https://pip.pypa.io/en/latest/installing.html – Paolo Stefan Aug 07 '14 at 07:56
  • 3
    install python 2.7.10 which has by default pip in it.Then use python -m pip install Django in cmd – Saurabh Nov 30 '15 at 08:19
  • PS D:\simcut> curl https://bootstrap.pypa.io/ez_setup.py | python File "", line 3 StatusCode : 200 ^ SyntaxError: invalid syntax – Mona Jalal Feb 09 '17 at 00:57
  • Doesn't work: `The request was aborted: Could not create SSL/TLS secure channel.` – Tomáš Zato Oct 20 '18 at 10:51
  • After Python 3.8.3 installation on Windows, I added 2 directories to my User Path (go to change environmental variables, click on button at the bottom "environmental variables"): for python: `C:\Users\USERNAME\AppData\Local\Programs\Python\Python38-32` for pip3: `C:\Users\USERNAME\AppData\Local\Programs\Python\Python38-32\scripts` I had installed Python in my local appdata, which was recommended, you might have it in your programs folder instead. After this, you can use `pip install ` or `python -m pip install ` in any terminal, as many stated here. – questionto42 Jun 18 '20 at 19:20
85

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:\Python\Scripts\
pip.exe install <package-name>

So in your case it'd be:

pip.exe install mechanize
DavidG
  • 24,279
  • 14
  • 89
  • 82
Leif Gruenwoldt
  • 13,561
  • 5
  • 60
  • 64
  • 15
    +1 because this explicitly says WHERE to type "pip install " most other guides, here and elsewhere, almost takes for granted that I would know this. – Rasmus Larsen Jul 24 '14 at 08:07
  • 1
    as said this is a great answer! It of course assumes python is installed in c drive. For people using PowerShell, in case you install python to a directory whose path has a space in it, use cd ("path") to change the directory. – dragonfly02 Sep 23 '15 at 20:59
  • This worked great on Windows 10, even with Python 2.7. Thanks for Windows-oriented answer that didn't make my eyes glaze over. – brichins Jun 03 '16 at 15:50
  • 1
    For some Windows installations, `pip` is located as `C:\Users\[you]\AppData\Local\Programs\Python\Python[XX]\Scripts\pip` – jpsecher Jun 09 '16 at 09:30
  • 7
    Or `python -m pip install `? – dumbledad Mar 10 '17 at 15:37
53

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

runejuhl
  • 2,147
  • 1
  • 17
  • 17
goldenratio
  • 1,026
  • 14
  • 24
22

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

Raja
  • 3,477
  • 12
  • 47
  • 89
Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
  • 2
    Thanks for your response! Where do I unpack it and where would I run that command? – echoblaze Sep 19 '09 at 21:07
  • 3
    If you downloaded the tar file, just unpack it with a program like WinRAR. Once you've done that, open up the command prompt and navigate to the folder where it was unpacked (You'll know you're at the right spot if you see a `setup.py` file). From there you can run `python setup.py install` and it will install it for you. – Evan Fosmark Sep 19 '09 at 21:27
21

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

python -m pip install [package-name]
phil294
  • 10,038
  • 8
  • 65
  • 98
12

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.

Community
  • 1
  • 1
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
3

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.

Community
  • 1
  • 1
Aseem Bansal
  • 6,722
  • 13
  • 46
  • 84
2

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>>
Lova Chittumuri
  • 2,994
  • 1
  • 30
  • 33
1

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>
PodTech.io
  • 4,874
  • 41
  • 24
0

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.

Kevin Horn
  • 4,167
  • 28
  • 30
0
PS D:\simcut>  C:\Python27\Scripts\pip.exe install networkx
Collecting networkx
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.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:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.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:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.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.

Mona Jalal
  • 34,860
  • 64
  • 239
  • 408
0

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.

Xantium
  • 11,201
  • 10
  • 62
  • 89
  • I do not have this shortcut in my start menu after normal Python installation 3.8.3 with VSCode, perhaps the newer versions have dropped this again? – questionto42 Jun 18 '20 at 19:02
  • It shouldn't have. Is Python added to path? @Lorenz – Xantium Jun 21 '20 at 10:54
  • 1
    I have the normal Python 3.8.3 installed, and I added to the user-defined environmental variables' Path variable: C:\Users\USER\AppData\Local\Programs\Python\Python38-32 C:\Users\USER\AppData\Local\Programs\Python\Python38-32\Scripts @Simon – questionto42 Jun 24 '20 at 12:34