Tweaking the PATH environment variable setting for Python (Windows)


Usually, you will use the Python Shell from within Idle or and IDE, but you sometimes you may need to be able to run  python within a terminal shell, e.g. to run setup.py for installing certain python modules. You may think that installing your Python system takes care of this as well, but it may not, so even your install went OK and you can run Idle, etc. you may still not be able to run the Python interpreter executable  via the command line i.e. within an old fashioned terminal shell, such as cmd.exe or the Windows Power Shell.

To test this, run cmd.exe, punch in python, and hit Enter - if you get something like the image above shows you're fine (you'll just get python 2.6 not 2.4), if it can't find python.exe read on. The python.exe in question should be within your python26 (for Python 2.6) folder, usually in C;|python26. Executing (running) that python.exe file from within any folder requires that Windows "knows" globally in which folder python.exe lives (i.e.you need to point it to that C:\Python26 folder). For this you have to append C:\Python26 to a environment variable called Path (the executable or DOS path), which sounds scary but is actually pretty simple once you know where to look.

The Python Windows FAQ  (http://docs.python.org/faq/windows.html) describes this adding (appending) of your python folder a bit down (search for DOS Path) and points to a video describe this tweak (http://showmedo.com/videos/video?name=960000&fromSeriesID=96).

Here's more on how to use cmd.exe  (http://www.voidspace.org.uk/python/articles/command_line.shtml), search for PATH to get to the part where the Path environment variable is tweaked.

BTW, I've been using the Windows Power Shell instead of cmd.exe which  came standard with Windows 7. It seems to behave more like the Unix shell (bash, sh) that I'm used to (yes, it understands ls!).

2 comments:

Jia Ma said...

The command sudo easy_install pywapi
works for my MAC.

Jia Ma said...
This comment has been removed by the author.

Search This Blog