Monday 21 March 2011

How to install a Python module in Windows?

The Python documentation is very detailed on how to install Python modules: you simply type something like this at the terminal window:

python setup.py install

The problem is, how do you do this in a Windows-based PC? I tried the following but it didn't work:
  1. Open a command prompt by type "cmd" at the "Run..." option from the start menu (I'm using Windows XP)
  2. Navigate to the folder where we have downloaded our Python module
  3. Type python setup.py install
When I tried that I got this error message:

'python' is not recognized as an internal or external command, operable program or batch file.

The problem is that the path of the executable python.exe is not listed in the PATH environment variable. I went round the problem by typing the exact location of the executable:

C:\python27\python setup.py install

But then I got another error! It turns out that the package I wanted to install requires another package called setuptools... back to the drawing board.

Fortunately I found documentation about setuptools. The module is packaged for a range of distributions including Windows, I only need to run its executable to install the package. And the good thing of this module is that provides a program called easy_install, which is located in C:\Python27\scripts. With this program you can actually install many other packages. It will download the package, install it, and solve any possible dependencies by downloading and installing additional packages.

So, to install a new Python package, say, suds, in a Windows PC, my current sequence of steps was:

  1. Open a command prompt as before.
  2. Type C:\Python27\scripts\easy_install suds

End of story! and it works! for me, anyway. You can find additional documentation about easy_install here.

13 comments:

chintan said...

Great work!!
Keep it up

GamesBook said...

FYI, if you install Python on Windows with Python(x,y) - www.pythonxy.com - then easy_install comes 'for free', and you can run both this command, and python itself, from inside of any directory.

ZEE said...

Thanks for the info... ,-)

Xnuiem said...

thank you

Jake Bathman said...

Ahhhh good lord, I was trying to figure this out for hours yesterday. I was confusing the windows shell (cmd) with the Python shell, and didn't really "get" it. Thanks for being concise, and not skipping any steps.

Unknown said...

You saved my life!!!

Unknown said...

Nice to hear that this blog post is still relevant... thanks all for your feedback!

Monica said...

Thank you, thank you, thank you!

sluiperbad said...

Dear Sir,
I tried to install Python modules in my Windows pc by the simple way you described in Diego's Musings.
But I didnot succeed..
After the prompt I typed: C:\Python34\scripts\easy_install numpy.
Downloading etc. happened, but at the enmd I was told that

freetype, png cannot be built.
Error: Setup script exited with 1

What is wrong?
I have Windows 7 and Python 3.4.
Best regards,
Hans Slingerland
email: sling@hetnet.nl

Unknown said...

Probably the problem is not with easy_install but with numpy? Do a web search with the error message and... good luck! Sorry I can't help, this problem did not happen to me.

sluiperbad said...

Sorry, mistake...
This error message I got after trying to install matplotlib.
Trying to install numpy resulted in the message that it needed C++ 10.0.
Although I got C++ 10.0 I didnot succeed in installing numpy...
What's wrong with my C++ 10.0 ???
Hans Slingerland

Unknown said...

Got an error saying -

File "c:\users\arkham\appdata\local\temp\easy_install-nghseq\suds-0.4\suds\__i
nit__.py", line 154, in
ImportError: No module named 'client'

Can u help me with this

Sumeet Vyas
(vyassumit1994@gmail.com)

Unknown said...

Hi Sumit, your error message is about suds, are you trying to install suds? Do a web search with part of your error message, for example search using this string:

ImportError: No module named 'client'

You might find the answer! Good luck