Python is pretty easy to install on Windows, but sometimes you need to do a few extra tweaks to really get the most our your development environment. In this article, we will try to cover all the common things you might want to do or install to get an ideal Python Windows development workspace set up. Some of you might think that all you need to do is install Python and you're done, but if you're going to do Windows development, then you'll need a few other packages to make it nicer.
Download Python and run the installer. Make sure you got the version you want (i.e. Python 2.7 or 3.x). You'll also want to make sure you get the bit type you want as there's a 32-bit and a 64-bit version. Note: The 32-bit Python will run just fine on a 64-bit system, but not vice versa! Once you've got that installed, we'll move on.
Now we’re going to make sure Python is set up right. Open a command window by going to Start –> Run and then typing “cmd†and pressing enter or return. Try typing “python†(without the quotes) in there and hitting your enter key. If you see the Python shell, then we’re halfway there. It should look something like this:
If you don’t, then we need to modify some settings.
On Windows, it can help a LOT to modify your Path settings by adding your Python path and the path to the Scripts folder to your System Path. Here's one way that you can do it:
Now you should be able to run Python from the command line. Not only that, you'll also be able to run the special scripts that were in Python's Scripts folder. Why would you care? Well, if you install easy_install / SetupTools or pip, they will install stuff in the Scripts folder that you can run. Speaking of which, since you now have a brand new installation of Python, let's take a moment to show you how to install a 3rd party package.
We will use pip as our example. It is used for the easy installation of Python packages from the Python Packages Index (PyPI, not to be confused with PyPy). Anyway, you'll need to go here to download it. The pip package is in a tarred and gzipped download at the bottom of the page. You'll probably need something like IZArc or Filzip to unzip it since Windows doesn't unzip tar files natively.
Open up a command line window as you did before. Now you will need to use the "cd" command to change directories to the location that you unzipped the files to. This can take some practice. On my machine, I usually unzip to my desktop and just cd there and then into the unzipped package. Once you're in the folder that has the setup.py file in it, all you need to do to install it is to type the following:
python setup.py install
Most of the time, this works great and the package is installed correctly. Occasionally, you will run into certain packages that complain that they need a compiler. If you don't have one installed (like Visual Studio or MingW), then you won't be able to install the package this way. You will have to find a pre-packaged installer for it. On my machine, I usually have easy_install installed too. For some reason, the package is called SetupTools . Anyway, the main reason that you used to need easy_install was that it was the defacto standard for install Python Eggs, which you can read about here or here. Now you can use pip or distribute to do the same thing. All three can also install packages that are in compressed archives. Normally, all you have to do to install a package with one of these utilities is something like this:
easy_install PackageName
pip install PackageName
Read their respective docs for more information though.
If you are a serious Windows developer who will need access to Windows APIs, then you will require the PyWin32 package. You'll want to become familiar with ctypes too, but that's been included with Python since version 2.5. PyWin32 is a lightweight wrapper around the Windows APIs. You can actually look on MSDN for the API documentation and almost directly translate it into Python. The ctypes package put on an even lower level and can be used to interact with DLLs directly, among many other things.
Another common need when programming on Windows is access to Window Management Instrumentation (WMI). Fortunately, Tim Golden has written a nice wmi module. You can usually get the same information using PyWin32, but it's more convoluted than just using WMI. Tim Golden has also written several other utilities:
You should also check out his awesome "How Do I" series of tutorials.
Finally, Python includes a module called _winreg that you can use to gain access to the Windows Registry. It's a very powerful tool that's very useful if you do a lot of administrative scripting on Windows.
The comments section started filling up with people mentioning the special Python installations you can get that actually include PyWin32 and other packages all wrapped up in one installer. That is also an option. Here are a few of those:
You should now have all the tools you need to be an effective Windows developer with Python. If you need help, the PyWin32 and ctypes mailing lists are active and they have experts there that can answer just about anything you'd want to know about those packages.
Copyright © 2024 Mouse Vs Python | Powered by Pythonlibrary