# Setting up Python in Windows 7

An all-wise journalist once told me that “everything is easier in Linux,” and after working with it for a few years I’d have to agree — especially when it comes to software setup for data journalism. But …

Many newsroom types spend the day in Windows without the option of Ubuntu or another Linux OS. I’ve been planning some training around Python soon, so I compiled this quick setup guide as a reference. I hope you find it helpful.

Set up Python on Windows 7

Get started:

1. Visit the official Python download page and grab the Windows installer. Choose the 32-bit version. A 64-bit version is available, but there are compatibility issues with some modules you may want to install later. (Thanks to commenters for pointing this out.)

Note: Python currently exists in two versions, the older 2.x series and newer 3.x series (for a discussion of the differences, see this). This tutorial focuses on the 2.x series.

2. Run the installer and accept all the default settings, including the “C:\Python27” directory it creates.

3. Next, set the system’s PATH variable to include directories that include Python components and packages we’ll add later. To do this:

• Right-click Computer and select Properties.
• In the dialog box, select Advanced  System Settings.
• In the next dialog, select Environment Variables.
• In the User Variables section, edit the PATH statement to include this:
C:\Python27;C:\Python27\Lib\site-packages\;C:\Python27\Scripts\;

4. Now, you can open a command prompt (Start Menu|Accessories or Start Menu|Run|cmd) and type:

C:\> python

That will load the Python interpreter:

Python 2.7.3 (default, Apr 10 2012, 14:24) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or license for more information. >>>

Because of the settings you included in your PATH variable, you can now run this interpreter — and, more important, a script — from any directory on your system.

Press Control-Z plus Return to exit the interpreter and get back to a C: prompt.

Set up useful Python packages

1. setuptools offers the helpful easy_install utility for installing Python packages. Grab the appropriate version for your system and install.

2. pip is another package installer that improves on setuptools. Having pip and setuptools will cover most of your installation needs, so go ahead and add pip. Now that you’ve installed setuptools, you can add pip by typing the following at any Windows command prompt (not in the Python interpreter):

C:\> easy_install pip

Notice that easy_install executes without needing to be told where on the system it’s located. That’s the benefit of adjusting your PATH variable earlier.

3. Mechanize and BeautifulSoup are must-have utilities for web scraping, and we’ll add those next:

C:\> pip install mechanize C:\> pip install beautifulsoup4

4. csvkit, which I recently covered here, is a great tool for dealing with comma-delimited text files. Add it:

C:\> pip install csvkit

You’re now set to get started using and learning Python under Windows 7. If you’re looking for a handy guide, start with the Official Python tutorial.

Need to set up on Windows 8.1? Here’s my guide.

### 145 responses to “Setting up Python in Windows 7”

1. Anthony says:

Any other useful utilities to add?

2. Mike Stucka says:

You probably ought to tell ’em specifically to download the older, 2.7 version, as 3.1 is listed as well.

Looks awfully useful, though — thanks!

3. Anthony says:

Duly noted, Mike. Thanks!

4. Ian says:

Thanks Anthony! As a long time Mac/Linux user, this tutorial was incredibly helpful in setting me up with a Python environment for my fresh Windows7 install.

5. Anthony says:

Glad it was helpful! A bunch of people are getting ready for some Django training at work this week, and someone passed this link around:

http://docs.python-guide.org/en/latest/starting/install/win/

Some good tips in there too.

6. […] following are bullet points gathered from walkthroughs created by Anthony DeBarros and the Kenneth Reitz’s Python Guide to get a Python development environment up and running […]

7. Sumit Kumar Jha says:

My python compiler is showing message:

Traceback (most recent call last):
File "F:\Python\latex2wp.py", line 657, in
s=extractbody(s)
File "F:\Python\latex2wp.py", line 140, in extractbody
for i in range(1,(len(L)+1)/2) :
TypeError: 'float' object cannot be interpreted as an integer
>>> 

Please help

8. Anthony says:

Sumit,

It seems that your code is attempting to load an object of type “float” into an integer. I’m guessing that’s due to the division operation occurring in the range method.

You may want to explore StackOverflow or scan the Python docs for handing type casting.

9. Joshua Grigonis says:

I recommend installing 32 bit, unless you need 64 bit. No, you probably don’t need 64 bit.

10. Jussi Jumppanen says:

Another way to install and run Python code on Windows is to download and install the Zeus IDE, create a new Python file and then use the run menu to run the script. And here is a video to see for yourself – http://www.youtube.com/watch?v=9vchdcLFW54

11. Anthony says:

Joshua: Thanks. You’re right, and I’ve updated the post to point people to 32-bit.

12. Tom says:

Or you can use npackd to install and optionally upgrade if need ever arises.

13. Ken Pierce says:

For some reason the python set-up universe eludes me. For instance I was trying to run easy_install in python. Once I realized that the emphasis was cmd prompt, not python prompt it fell in place. A note to that effect might really help the uninitiated.

14. Anthony says:

Ken: Thanks; that’s a good point about differentiating between the Windows cmd prompt and the prompt inside the Python interpreter. I added some words to emphasize that.

15. Marion says:

I installed python on my computer, I have windows 7, but when i write python on the command prompt it displays the following message: ‘python’ is not recoghnizes as an internal or external command, operable program or batch file. How can I fix this issue?
Thanks

16. Anthony says:

Marion, you need to follow Step 3 in my tutorial above.

17. Henry says:

I’m getting this error when installing mechanize module in python 3.2
——-

C:\>pip install mechanize
Downloading/unpacking mechanize
Downloading mechanize-0.2.5.tar.gz (383Kb): 383Kb downloaded
Running setup.py egg_info for package mechanize

Installing collected packages: mechanize
Running setup.py install for mechanize
File "C:\Python32\Lib\site-packages\mechanize\_beautifulsoup.py", line 267

raise AttributeError, "'%s' object has no attribute '%s'" % (self.__clas
s__.__name__, attr)
^
SyntaxError: invalid syntax

...  snip ...

Successfully installed mechanize
Cleaning up...

——-
it finished saying “successfully installed mechanize”. When importing mechanize in a script it triggers an error, any clue?

18. Anthony says:

Henry,

You’re getting the error because Mechanize does not support Python 3.x at this time.
I’ve edited your comment for readability.

19. Meklit says:

Hi Anthony,

I have tried to install python 2.7 on my windows7 following the steps but it failed and the following message pops up. An error occurred during the installation of assembly ‘ Microsoft.VC90.CRT, version = ‘9.0.21022.8’ publickeytoken=’1fc8b3b9a1e183b”,processorArchitecture=’x86”,type=win32”

I noticed that I have the 2.5 version and I assume this is while I was installing ARCGIS on my pc. I wouldn’t mind using the 2.5 version the only problem is I can’t get the langague interpreter run as per your steps…I get the following message ‘python’ is not recoghnizes as an internal or external command, operable program or batch file.Any insight??

20. Anthony says:

Meklit,

Sounds like your system may have had a problem with a prior Windows install. A little Googling turned up this: http://support.microsoft.com/kb/970652

That said, if you want to use the Python 2.5 install that ESRI includes with ArcView, you should be able to by modifying the system PATH I mention in Step 3 above to point to the required Python components.

The only issue is that, at least on my system, I see that ESRI adds a directory between the Python folder and the components. So, for me, I’d have to set the PATH to:

C:\Python26\ARCGIS10.0;C:\Python26\ARCGIS10.0\Lib\site-packages\;C:\Python27\ARCGIS10.0\Scripts\;
21. shubhasmita sahani says:

hi ,
i trying to learn Python by self.I amusing widows -7 32 bit machine ,i am facing some problem while installing it.Can anyone please gove a proper link and proper setup which will exactly sit on my machine properly. I will be reallt greatful. Thank you.

22. Anthony says:

shubhasmita,

Without more details I don’t think I can help.

23. Dusti says:

I just wanted to add a note to let you know that I am new to the whole idea of programming and am trying to take a class that required python. I can’t tell you how helpful this little tutorial was. Thank you so much for taking the time to put this up here.

sincerely,
Dusti
To get something you have never had,
you must do something you have never done.

24. Anthony says:

Dusti,

Really glad it helped!

25. Lubaba says:

Hi Anthony,
I installed python 2.7.3 (python-2.7.3.msi for windows) on my windows 7 machine. However, I could not run python scripts from Python GUI IDLE. I am getting an error “There’s an error in your program: invalid syntax” each time I try to run my script. I tried to run the same script from python command prompt, it worked. What could be the possible reason of this issue? As I am not very comfortable working on command line, it would be a great help if you could offer a solution. Thanks.

26. Anthony says:

Lubaba,

I never use IDLE so I don’t have a lot to offer for troubleshooting. I found this from a quick Google search:

http://stackoverflow.com/questions/6513967/running-python-script-from-idle-on-windows-7-64-bit

27. Matthew says:

i downloaded python and changed the path variable to C:\Python27;C:\Python27\Lib\site-packages\;C:\Python27\Scripts\;
and i go on cmd prompt and type C:\> python and i get this
‘C:\’ is not recognized as an internal or external command, operable program or hatch file
plz help!
thanks

28. Anthony says:

Matthew,

Just type “python”. In the example, the “C:\” represents the prompt itself.

29. Matthew says:

ok thanks you are a life saver

30. Dacio says:

Hi Anthony

I installed python 2.7.3 in my box running windows 7 32 bits. Everything was fine until I wanted to print from my program, Then I got : “ImportError: no module named win32print”.

This is what I get about my path:

>>> import sys
>>>> print sys.path
['', 'C:\\Python27\\Proyectos\\%PYTHONPATH%', 'C:\\My_python_lib', 'C:\\Windows\
\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python
27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\
lib\\site-packages']


please any suggestion/advice.

thanks in advance

31. Anthony says:

Dacio,

Haven’t run into that one. Perhaps this helps?
http://www.blog.pythonlibrary.org/2010/02/14/python-windows-and-printers/

32. Karl says:

Anthony

Thank you very much this was a very easy to follow and very useful tutorial. You have saved hours of web browsing.

33. h-man says:

I’ve followed your direction installing Python 2.7.3 32 bit on Win7 64 bit HP. Python starts in command prompt but IDLE will not start from Start/All Programs/python27. Any ideas?

34. Anthony says:

h-man,

Hmm. That’s one of those situations that’s difficult to diagnose because it’s probably related to something specific on your machine. I do see that others have run into the problem — this thread discusses a firewall as being an issue: http://bit.ly/S8xRRQ

35. Jeff says:

Do you have a recommendation for a text editor? It would be useful to have a color coded script…

36. Anthony says:

Jeff,

I particularly like Sublime Text 2, which you can try for free. Buying a license allows for installation on multiple machines.

A lot of coders swear by Vim, which has its own paradigm for editing and requires some time to learn. I’ve used it — and it’s a must if you’re going to work on remote servers — but I still like Sublime better.

37. John says:

I have set up the path to C:\Python27\Lib\site-packages\;C:\Python27\Scripts
and I cant run the scrip by > python full\path\to\myscript.py command on window 7
so what shall i do
thnaks

38. Anthony says:

John,

What error message do you receive?

39. Iris says:

Hi Anthony,

Thank you very much for the clear and to-the-point tutorial 🙂 It has saved me a lot of searching and headache.

40. csbellina says:

This was SO SO SO SO SO SO helpful!!!! thank you so much!

41. Anthony says:

Iris, csbellina,

You’re both very welcome. It’s been rewarding to be able to help people. Ironically, I recently moved from Windows to OS X for my daily work — and found myself frantically searching for good Python setup guides!

42. dran001 says:

Here is a very important one for ArcGIS desktop.
Besides setting your PATH environment variable, add a new variable “PYTHONPATH” if it is missing, and set/add “;%ArcGISHome%\bin”.
In my case, it looks like: PYTHONPATH=C:\ArcGIS\bin
when it type >set PYTHONPATH in a cmd window.

For some reason this was missing when I installed ArcGIS desktop 9.3.1 in Windows 7.

43. Alejandro says:

I’ve been searching for a tutorial that in a really concrete and easy way describes the process to install python and pip. This is just what I was searching for! Thanks man!

44. windmill says:

Dear Anthony

I have struggling to load the interpreter – section 4 – system throws up an error message

windows cannot find c:\> python directory

45. Anthony says:

Windmill,

Make sure you’re only typing “python” at the C: prompt and not “C:\> python”.

46. Sandepp says:

Thank you Anthony it was very helpful for windows refugee(me)

47. Andrew says:

Excellent article mate !! Got me up and running with python in no time . Keep up the good work.

48. wani says:

i already installed python 2.7.3 on my system(window 7)
i can run simple python code
but,i face a problem when i want to run script that contain import beautifulsoup
do i need to install all those setuptools,pip and mechanize to make its working??
i have googled for the solution for days about how to install the beautifulsoup unto my python,but,still i couldn’t find any right solution..
i keep uninstalling if it does not working
could u please help me how can i make it work on my system??

49. Igor says:

Thanks a lot for the article!

50. Anthony says:

wani,

I am confident that if you install setuptools and then pip, you can install Beautiful Soup with pip as I mention above. The Mechanize library is not a prerequisite for Beautiful Soup.

51. wani says:

tq so much anthony…so helpful!!

52. tunde says:

hello, i installed python 3.3 please and it seem this article talks abt 2.7 only..any help regarding python 3.3 as i am a novice in programming..i have installed the python 3.3 and when i type “python” python at start, the only programs i see are python(command line) and IDLE(python GUI). I can’t find anything like python interpreter and i don’t know how to go about writing and running the python codes. The little amount of python that i learnt was learnt online and the interpreter was online too, so now, i want to start soding offline. Help please

53. Anthony says:

tunde,

You should set your PATH variable according to the directory where Python 3.3 was installed. It would probably be something like:

C:\Python33;C:\Python33\Lib\site-packages\;C:\Python33\Scripts\;

Then, you should be able to type “python” at a command prompt to launch the interpreter. Beyond that, the various Python libraries I mention here may or may not be available under 3.3 — you’ll have to do some research.

54. jeff says:

I am having trouble with python, django, heroku install.

ive run:

python winservice_install

because djcelery has to be run as a web service on windows 7 (64 bit)

but when i run:

python manage.py winservice_install

it tells me it can’t find win32api

pprint(sys.path) includes

D:\\apps\\python\\lib\\site-packages\\win32′,
D:\\apps\\python\\lib\\site-packages\\win32\\lib’,

and one of these directories has: win32api.pyd is that what it wants?

I’m a beginner with python, heroku, and django: it’s been an entire day and I would like to know how to have python find win32api

thanks!

55. Anthony says:

Jeff,

Sorry, but I don’t readily have the answer to your question. But I do have a broader suggestion:

If you’re going to be developing a Django app, I’d strongly suggest you do so on Linux or Mac OS X. Is it possible to develop a Django app on Windows 7? Sure. But I’ve found over time that installing Python libraries and getting everything working well is much more complicated compared with running Python under Linux.

You don’t need to have a separate computer, either. Go install VirtualBox (for free) and download Ubuntu (for free). Guaranteed to make life simpler in the long run.

https://www.virtualbox.org/wiki/Downloads

56. Marcus says:

YOU SIR ARE A HERO! Thank you so much I have been trying to figure this out as a newbie for a long time and you explain things step by step in easy to follow instructions for us newbies.

57. William says:

Installation of “pip” for Windows users (I am on Win 7 (x64):

1. cd to the directory where the pip Win installer downloaded from https://pypi.python.org/pypi/pip was downloaded to.

2. In a Administrator’s command prompt do the following
> easy_install .
Note:there is a full-stop after the word easy_install

Now you can run commands like
>pip install mechanize

Have fun! 🙂

58. William says:

Thank you Anthony.

Nice work!

🙂

59. Abhas says:

Thank you for this whole article. Basically, I am using python for over 6 months on windows and I always used those python extension installers from unofficial sites. Sometimes I couldnt even find some important extension as an installer. It felt really limited….
And today after I found your article and did all the steps, the whole process felt like a breeze..
No nerdy compilations, nothing.. Again, thanks…
I am actually looking at the date of the post and thinking how some basic posts can help others for a long time ever after. And btw, now I’ll be hunting your site for other python-related articles..
You just earned yourself a loyal reader…
Again, thanks from the bottom of my heart..

60. Shyju Varkey says:

Thank you very much for this excellent article. I have been using Python in Linux for quite some time and wanted to try it on Windows. You article made my work so easy. I haven’t found such a detailed and perfect installation guide ever. Thanks Again.

61. Maurice says:

Making a path environment variable to the folder containing Python.exe is easy. What you do not explain is how to make Python locate a Python script from a path setting. For instance I have this Python script in the path C:\Program Files\pyurlsnooper\pyurlsnooper-gtk.py, but I have to change into the pyurlsnooper directory to run the script. Adding a Windows path to C:\Program Files\pyurlsnooper does not make the script accessible to Python anywhere other than from it’s installation folder. I tried adding this path to the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.7\PythonPath but still Python cannot locate the script anywhere except from it’s installation directory. Could there be a problem with the space in ‘Program Files’?

Also what is the point of making WIndows paths to C:\Python27\Lib\site-packages and C:\Python27\Scripts if these folders do not contain Windows executables?

62. Anthony says:

Maurice,

The reason I add the \site-packages\ and \Scripts\ subdirectories to my PATH is because I occasionally find that certain Python libraries seem to need that reference to function. For example, the csvkit library I recommend in this post installs Windows .exe files in the \Scripts\ subdirectory.

For the other issue you mention, these might help:
http://docs.python.org/2/install/#inst-search-path
http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7

63. Rich says:

So, I installed Python 2.7 into Win 7 and added the variable as outlined in step 3. Does it matter what the variable is named? I have tried Python and python, but when I go to a command prompt, I get the not recognized as a program…etc message. What am i doing wrong?

64. Rich says:

I posted a bit ago, looks like it was removed. Anyway, I figured out why it wasn’t working. the Script directory isn’t created automatically. Presumably, it does after the setuptools gets installed, but if one if following step by step, the Scripts directory must be manually created for step 3 to actually work.

65. Anthony says:

Rich,

It’s true that the Scripts directory is not created until SetupTools is installed, but that shouldn’t prevent you from executing python from the command line. One thing you must do after Step 3 is quit and restart your command terminal for the new path to be recognized.

66. Raj says:

Hi Anthony,
I’m using Python 2.7.2 version / pyodbc 32 bits installed in a Windows 2003 server, which also has IIS server configured for sending mails. I’m trying to connect through my Excel to Teradata and refresh the graphs / charts / Table. For the same I have written macros to refresh the table / charts .Through Python I’m retying to open the Excel get a snapshot and send it an email

I’m getting the following error


import win32com.client as win32;
File "c:\Python27\lib\site-packages\win32com\__init__.py", line 5, in

import win32api, sys, os
ImportError: DLL load failed: %1 is not a valid Win32 application.


When I search for solution it looks like I have to install 64 bit Python. But I’m worried whether my other setups will get disturbed. Is there a way that I can open the Excel / Macro using 32 bit?

Your help is much appreciated. Thanks in advance

67. Rich says:

Hmm. I was restarting the command shell, but as soon as I created the scripts directory, it worked, even before installing the setup tools. Anyway, besides that, I got it up and running. Thank you much!

68. Anthony says:

Raj: Unfortunately, I don’t have enough experience to offer a meaningful answer.

69. Rob says:

Many thanks for this. It made the whole installation process much easier.

70. […] wish I read this quick and clear guide on how to set up Python in Windows 7 before I started diving through Python’s […]

71. […] version, as flask has not yet been ported to python 3. Here is a nice and simple guide to do that, here  ( Thanks to Anthony DeBarros for the guide. You can follow […]

72. Ned says:

This is awesome!!!! Thanks so much for putting this together.

Much love

Ned

73. mahdiye says:

hi. i have a problem . i dont know which version i shoulde use for windows 7. please help me . i really want to know python but i’m a begginer .i only know visual basic. help me. which version?? thanks

74. Anthony says:

mahdiye,

If you’re just getting started, I’d suggest Python 2.7.5, which is the latest version in the 2.x series. Python 3 is rapidly gaining traction, but there are still a number of helpful libraries that aren’t yet ported to version 3 yet. You also can make the transition later to 3 if your needs change.

75. mahdiye says:

Anthony,
thanks Anthony . i downloaded it . i really want to learn python then i downloaded some flv files for learn. the name is : CBT Nuggets – Python Programming Video Tutorials
i watched some of these videos then i started to writting codes but i had some problems .i followed the codes that i learned but i saw errors like syntax error etc.
look at this :

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> def gensq(n):
for i in range(n):
yield i**2

>>> a=gensq(4)
>>> a

>>> type(a)

>>> next(a)
0
>>> next(a)
1
>>> next(a)
4
>>> next(a)
9
>>> next(a)

Traceback (most recent call last):
File "", line 1, in
next(a)
StopIteration
>>> def itsq(n):
result=[]
for i in range (n):
result.append(i**2)
return result

>>> b = itsq (4)
>>> b

………………………………
i know they are ridiculous its because i dont know anything about python and just followed the codes.
and i have a problem. i cant find graphycal user interface of python.
…………………………………
sorry my english is not so good . i’m a iranian 16 girl ^^
. help me 🙁

76. Anthony says:

mahdiye,

There are some good books here that might help you get started:
http://pythonbooks.revolunet.com/

77. zafrul izham says:

very usefull..
salute from malaysia 🙂

78. Leslie says:

Thanks so much. pip install is great. One question on csvkit. I have Windows Vista 32-bit. cvskit commands work fine. But piping and ‘head’ (the unix shell) does not work. How do you use csvkit as shown in the csvkit tutorial on Windows? Thanks so much.

79. Anthony says:

Leslie,

If you want to emulate Linux command-line functionality on Windows, your first stop should be Cygwin:

http://cygwin.com/index.html

80. Lesie says:

Anthony, I took the advice you gave to someone in this thread about a running linux as a VM on windows. So… I installed VirtualBox and am running ubuntu server in it. I installed csvkit. I also connected with a terminal running on windows using putty, so now I am ready to learn bash and use the csvkit. I do want to do a web application in python. I am currently learning on windows using google app engine and the built-in webapp2 framework. But when you said it is easier to do web app development on linux, I decided to install a linux VM. Next step: I have to buy a new computer with lots of memory and hard disk space so I can actually do development. Thanks so much for your blog. I am a follower!

81. Anthony says:

Leslie,

That sounds great. VirtualBox with Ubuntu works pretty well. You can also set up a Windows machine to dual-boot into Ubuntu. Either way, good luck on your learning. If you’re into Python and web development, I suggest you try out Django.

82. Amy says:

Thanks for the great information
Cheers
Amy

83. Imran says:

Hi,
I followed your instructions above to set up Python,
I get the following error message.

C:\>Python33
‘Python33’ is not recognized as an internal or external command,
operable program or batch file.new

I want to know where I have gone wrong?

Thanks.

84. Anthony says:

Imran,

See Step 4. The command is “python” not “python33”.

85. Kirsteen Mackay says:

Thank you for a very useful tutorial in getting Python installed on my Windows 7 machine.

86. Sharon says:

Thank you so much! it was so helpful!!!

87. Anthony says:

Kirsteen and Sharon,

Glad to help!

88. Coop says:

Hi,
Thank you so much for this tutorial. I’m a MATLAB/R programmer attempting to start using python for some web-scraping, but I am currently a novice with respect to command-line programming. I followed your first three steps (I did modify my PATH), but now, when I type ‘python’ into a command prompt, I receive:

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

If I change directories to C:\Python27, I can then type ‘python’ and enter the interpreter.

Typing:
>>>import sys
>>>print sys.path

Reveals:

[[”, ;C:\\Windows\\system32\\python27.zip’, ‘C:\\Python27\\DLLs’, ‘C:\\Python27\\lib’, ‘C:\\Python27\\lib\\plat-win’, ‘C:\\Python27\\lib\\lib-tk’, ‘C:\\Python27’, ‘C:\\Python27\\lib\\site-packages’]

So…if the PATH statements seem correct, why can I not type ‘python’ from any command prompt and enter the interpreter? (And subsequently, why can I not easy_install pip?)

Sorry for the long question – I’ve been at this for a couple days and have grown frustrated.

89. Anthony says:

Coop,

If you open a command prompt in Windows 7 and type “path” (without the quotes) and press Enter, what displays? Most important, are the Python directories listed there?

90. Coop says:

When I enter “path” (without the quotes, of course) into the command prompt, I see the following:

PATH=C:\Perl64\site\bin;C:\Perl64\bin;C:\Windows\system32;C:\Windows;C:\Windows\
System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel
\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files
(x86)\Lenovo\Access Connections\;C:\Program Files\MATLAB\R2009a\bin;C:\Program F
iles\MATLAB\R2009a\bin\win64;C:\Program Files\TortoiseSVN\bin;C:\Go\bin;C:\Progr
am Files\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files (x86)\SSH Communications Se
curity\SSH Secure Shell; C:\cygnus\cygwin-b20\H-i586-cygwin32\bin; C:\Python27;
C:\Python27\Lib\site-packages\; C:\Python27\Scripts\;

Much of this old stuff that has been in my path for some time. It seems the python information is present. Am I missing something?

91. Anthony says:

Coop,

Edit your path to get rid of any spaces after the semi-colons. Close and re-open your command prompt window. See if that works.

92. Coop says:

Brilliant! Removing the white space fixes the problem. Onto the next steps of the python journey. Thank you so much for the help!

93. Anthony says:

Coop,

Awesome. It’s always great when stuff works.

94. Anca says:

Hello! Thanks for this tutorial. I am new with python, but I must get better fast :)) Can you tell me some tools of python for dealing with .xml files?

95. Anthony says:

Anca,

You’ll want to look at BeautifulSoup and lxml:

96. Justin says:

I am new to learning Python. I have both Python 2.7 (32 bit) and Python 3.3 (64 bit) on my computer. When I downloaded Python 3.3 it gave the option to adjust the PATH setting, I did that. I am curious as to if I manually adjust the PATH for 2.7, will it cause any issues with 3.3 also on the comp.? Would I be better off un-installing 3.3? Any advice would be greatly appreciated!! My goal in learning Python is to use it in conjunction with MySQL (learning that as well) so that I can keep updated sports stats databases. (I am hoping beautifulsoup and mechanize can help with web scraping to keep data up to date)

97. Anthony says:

Justin,

Both versions can happily coexist on your machine. You can manually change your PATH depending on which version you’re working with. Other people have tried other solutions, so it’s worth Googling to see the possibilities. Example:

http://stackoverflow.com/questions/3809314/how-to-install-both-python-2-x-and-python-3-x-in-windows-7

98. Justin says:

Thanks Anthony, I ended up just uninstalling python3 until if/when I ever need it. I have been trying to download setuptools for a couple of days now and having way more trouble than I probably should be. I have my PATH set accordingly and I downloaded the top file into my /site-packages directory and unzipped it. Now, I am supposed to download the ez_setup.py file into the same folder and run it. This is where I am lost. The file is a web address, so I wasn’t sure how to download it. My thought was to just copy the whole page and paste it into Python Shell and save it as a ez_setup.py , then run it on the command line. Would that be the correct strategy? When I try to run the ez_setup.py from the command prompt I get an error message …”no such file or directory” What am I missing?!? I check many stackoverflow threads to no avail!

99. Justin says:

So, right after I sent my last question, I ran the ez_setup.py file in the Python Shell to see what would happen and it started to work, downloading different files and stuff, but not long in there was an error, right after the line that said “installing setuptools”, the next line said “something went wrong during the installation.” and the next line “see the error message above.” I noticed a scripts folder was created, although it was created in a different spot than python27/scripts, it was created in a sub folder in the site-packages folder called setuptools-0.9.8-data and the easyinstall.exe file seems to be there. At least from this point, I can do some more research and try to find out what went wrong, hopefully I can figure out an answer.

100. Anthony says:

Justin,

You should just need to download the Windows installer from here and run it:
http://www.python.org/download/

It’s a .msi file, which is executable.

101. Justin says:

Sorry, I guess I didn’t elaborate clearly, I have Python 2.7 downloaded no problem, its downloading the setuptools where my issue is. I downloaded it (the top of the three download links) to the site-packages sub folder then ran ez_setup.py in the python shell and the download process started, but there is an error and the process didn’t finish. It seems the easyinstall executable file was created, as was a scripts sub folder, but the scripts sub folder wasn’t Python27/scripts it is Python27/Lib/site-directories/setuptools-0.9.8.data/scripts. I hope that makes sense.

102. Anthony says:

Justin,

I usually download the file to my desktop and run the .msi installer from there.

This one:
Python 2.7.5 Windows Installer (Windows binary — does not include source)

103. Justin says:

Anthony, thanks for trying to help.. maybe I am beyond help at this point! I already have that file downloaded onto my computer. The problem I am running into is trying to install the package “setuptools” that you refer to in the “Set up useful Python packages” section of your post.

104. Anthony says:

Justin,

My previous comment should be all you need. Don’t think I can offer any further help on this one. Thanks for reading.

105. Oliver says:

When installing Python 2.7.5 it says there is a DLL file missing, – and the installation is aborting.

Its right after choosing the installation path.

What to do??

106. Anthony says:

Oliver,

I’d start with Googling the specific error message to see whether it’s a common problem with a known solution.

107. Oliver says:

well i have tried to google it, but i haven’t found anything usefull…

here is the error message:
There is a problem with this Windows Installer package. A DLL required for this install to comlete could not be run. Contact your support personnel or package vendor.

108. Oliver says:

well, i just made it work… so have a good day and thanks for replying so fast.

109. Anthony says:

Oliver,

Care to share your solution? A lot of people come to this post — could help someone out there.

110. C.B.L.F. says:

Hi Anthony,

Thank you for this info. I do have one question in regards to step 3 under setting up python. When I get to the environment variables window, there exist a Path variable for User and System. Do I need to edit/update both User and System path variable with the statement you prescribed?

111. Anthony says:

Hi, C.B.L.F.,

The User variable section is the only one you need to change.

112. kev says:

Wow. thank you. Spent hours trying to figure this out. So many failed attempts.

Congrats on being the only person to explain the windows install COMPLETELY.

I’m going to take you advice nice and give linux a shot.

thanks again.

113. Jay L says:

I got as far as the following and cannot get any farther:

“Set up useful Python packages
1. setuptools offers the helpful easy_install utility for installing Python packages. Grab the appropriate version for your system and install.”

I successfully installed Python 2.7.5 on a Windows 7 machine, but I’m lost by what you mean by “grab the appropriate version [of setuptools and easy_install] for your system and install.” Are these additional packages that I need to download and install? Once I get these files, how do I run them? Are they installed from the Command prompt?

Thanks.

114. Anthony says:

Jay,

Yes, you must follow the link in the blog post to download and install setuptools. The instructions for installation are at the link.

115. […] To install python on your system, please follow the instructions on the following link, Its recommended to install python 2.7 as there are some syntax changes in new python:version 3 which is not backward compatible. http://www.anthonydebarros.com/2011/10/15/setting-up-python-in-windows-7/ […]

116. Maz says:

dear Anthony
thanks for make everything easy with python .. i have problem i followed all downland steeps but still cant find this area

C:\Python27;C:\Python27\Lib\site-packages\;C:\Python27\Scripts\;

where i can add (Scripts\;)…

117. Tony says:

This was an excellent tutorial. Thank you very much.

118. […] version, as flask has not yet been ported to python 3. Here is a nice and simple guide to do that, here  ( Thanks to Anthony DeBarros for the guide. You can follow […]

119. John says:

Thanks for this, I was constantly running in to problems getting pycrypto installed (more people have this), seems the solution was installing the x86 version 🙂

120. Force says:

Awesome , thank you very much and it is very helpful .
Keep up the good work.

121. Shane O Neill says:

You’re a lifesaver. I had been banging my head against a brick wall for hours trying to ‘pip install oauth2’ on Windows 8; searched all over the place and couldn’t find instructions that worked until I came to this page, and then it was sorted in 5 minutes.

122. Peter says:

Hi Anthony, I’m afraid I find your step three instructions somewhat confusing.

“3. Next, set the system’s PATH variable to include directories that include Python components and packages we’ll add later. To do this:

Right-click Computer and select Properties.
In the dialog box, select Advanced System Settings.
In the next dialog, select Environment Variables.
In the User Variables section, edit the PATH statement to include this:”

The System’s PATH variable (on my Win7 system anyway) is a System Variable not a user variable. So what do I do? Create a User Path vatiable or edit the system path one. Given the PATH already has content do I just add it on the end with a comma or delete what is there?

123. Anthony says:

Peter,

You can edit the System PATH. Add the Python paths at the end, after a semi-colon.

124. Dinesh says:

Hi Anthony I am using python 3.7 in windows 8 machine when I executing program
compiler showing error

Traceback (most recent call last):
File “C:/Python34/1.py”, line 2, in
import curses
File “C:\Python34\lib\curses\__init__.py”, line 13, in
from _curses import *
ImportError: No module named ‘_curses’

please help!!

125. bus7dz says:

thx great tutorial!

126. silver says:

more easy way to install python………follow the link

http://s4silver.blogspot.in/p/how-to-install-python.html

127. Antonio Marcos says:

Congratulations!
I could only configure easy_install with this post.
Thank U !!

128. shrey mishra says:

Hi Anthony,
I am trying to install pywin32.exe as i need to use autoit library in robot framework.
But as i click the setup it shows directory invalid could not create temporary file. How to fix this.

129. Andreas says:

Hi Anthony,

Best tutorial on the topic that I’ve read so far!

Many thanks!

130. Anthony says:

Many thanks!

131. Abhinav Raj says:

We are using a 32 bit version on a 64 bit environment won’t it cause any trouble such as incompatibility or slowing down of system.

132. Eugene says:

Hello, Anthony!) Many Thanks for your gide! Only one thing, I can’t install Python on my computer with Win7! Error: …there is not DLL for install…” But after online installation version 3.5 I can’t to run IDLE( Python runs normaly)
Help me please!)

133. Robert says:

Excellent step by step instructions to install Python, Easy_Install and PIP

I initially received failure messages when I tried to install Mechanize and Beautiful Soup. However, because your instructions were so clear I was able to quickly rule out an issue with your instructions. I switched over to a different network connection and was able to successfully complete the installations. (There was a firewall rule blocking access on the first network connection.)

I also ran into the the issue with my path statement in Windows 7 being a part of the system variables as opposed to the user variables. Not sure if you can edit your original post, but it would save some time in scrolling through the comments, or doing a separate Google search for some readers.

Thank you for taking the time to publish this…
Robert

134. Ranjith says:

i am a linux engineer , my firm developed one django application for managing inventory,sales and purchase in small shops. we have installed it on one client system (in windows 7)

we are using python 2.7 with django frame work 1.5 while printing receipts with the application .we are getting the error “31, ShellExecute, A device attached to the system is not functioning” can you help me in resoving this issues

we are using the following code
=============================================================

import tempfile
import win32api
import win32print
import os

fillpath =  os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),"..",".."))
filename = fillpath + '\\sales_pdf.pdf'
print fillpath
print "**************"
win32api.ShellExecute (
0,
"print",
filename,

'/d:"%s"' % win32print.GetDefaultPrinter (),
".",
0
)

in the same system we have taken a print out side of the application with a python script , that we are able to take print successfully

the python script we have used out side of the application is given below

============================================================

import tempfile
import win32api
import win32print
import os

filename = "\Document.rtf"
win32api.ShellExecute (
0,
"print",
filename,

'/d:"%s"' % win32print.GetDefaultPrinter (),
".",
0
)


kindly guide me in resolving the issue

thanks in advance

Ranjith

135. munaraliyan says:

I am getting the following error.. what could be the problem.. i am behind a proxy server.

D:\XX\XXX\pywin32-219>pip install mechanize
Collecting mechanize
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ConnectTimeoutError(, 'Connection to pypi.python.org timed out. (connect timeout=15)')':
/simple/mechanize/


Python Version = 2.7.10

136. Hanseatik says:

IDLE does not start for python 3.5 64bit on windows 7.
I installed Python 3.5 after I uninstalled python2.7 and restarted and every things seems to be fine. But when I click on IDLE it does not start and gives no error.

137. Francesco says:

I would not suggest to install packages that the user could never use. You should update this guide adding instructions on virtualenv, that is painful to manage in Windows, but as a quick start install guide 5/5!

138. Joe Senter says:

Great article. Excellent Article.

139. […] you might need to add python to your path to be able to run scripts from the command line.This blog post has a simple set of instructions to add python to your […]

140. angie says:

hello Anthony…. I am trying to run the install pyCrypto as admi by I get this error…

C:\Windows\system32>rem If you want to decrypt android whatsapp msgtore.db.crypt
files, then you need to run this (after installing ActivePython)
_
Could not find the Python directory. Please make sure that ActivePython is insta
lled in either C:\Program Files (x86)\Python27 or C:\Program Files (x86)\Python3
2
_
Press any key to continue . . .

I installed both Python 32 and 64 several times on the program files directory and also on its own python27 directory/// nothing works…..do you think yo can help me I’ll greatly appreciate it….

141. Akash Tiwari says:

hii anthony i am getting an error pip command not found , but i have installed get-pip.py in my system can you help .

thanks in advance

142. […] Setting up Python in Windows 7 […]

143. ananymous says:

when i install the python 2.7.13 into my window 7 . all the cmd i am giving right but in the last step it gives me ( syntax error ) how to solve this problem any idea ?