Python on Windows
Setting up a development environment on Windows can be counterintuitive, especially if you're new to programming. Here's how to do it.
1. Installing Python
First, install the latest version of Python 2. It's included with DataNitro, and you can also get it directly from Python.org. You should use the "Windows x86 MSI Installer". If you're interested in trying other Python versions, see the bottom of the page for notes.
By default, Python is installed to the folder "C:\Python27". If you decide to put it somewhere else, note down where. You'll need this folder in a minute.
2. Connecting Python with Windows
The next step is connecting Python with Windows. You can do this by adding the Python folder to your Windows Path.
The Path is a list of folders that Windows checks when it
looks for a program. You can modify it by right-clicking "My
Computer" in the start menu, then clicking "Properties", and then clicking "Advanced system
settings" in the left bar.
Click "Environment Variables..." in the menu that comes up, and find "Path" in the bottom window (named "System variables"). Add the text
to the end of your Path. (If you installed Python in a custom folder, use that folder instead of "C:\Python27".)
This tells Windows to look in your Python folder, and two subfolders, when you run a command. (The semicolons are used to separate different folders.) This will let you run Python programs and manage your Python installation.
3. Python libraries
You now have Python installed and set up. The last step is to add a package manager, which will let you use Python's open-source libraries.
First, if you want to use numpy or scipy, you should download and install them directly. You can do so on the SciPy site. Make sure to download the right files (they should be .exe's) for your version of Python.
The standard Python package manager is called pip. To get it, install distribute and then pip. (Use the files ending in "win32-py2.7.exe". If you're not using 32-bit Python 2.7, you'll need different versions.)
When you want to install a Python package, run "pip
install <package name>" from the windows command line. (You can get
to the command line by typing "cmd" in the Windows search bar. If
you had the command line open before you changed your path, you
should restart it.)
Some packages won't install properly with pip, in which case you should use its predecessor, easy_install. This was installed alongside pip.
For example, you may want to install numpy, a numerical computation engine, to perform scientific computations. To install it, run "pip install numpy" from the command line. If you receive an error, run "easy_install numpy" instead. This will put numpy on your system.
To check that everything's worked so far, click your Start bar, go to "Python 2.7", and click "IDLE (Python GUI)". A window named "Python Shell" will come up, waiting for you to enter commands next to a prompt:
Type in "import numpy" and hit Enter. If Python comes back with another prompt after a second, everything's working correctly:
4. Getting Started
Congratulations! You've set up Python.
You're ready to start coding. If you're working with DataNitro, check out our Quickstart for an introduction. If you're learning Python, here are some good resources to get started:
- Learn Python the Hard Way
- 6.00x, MIT's Introduction to Python course on edX
- Codecademy's introduction to Python
If you have any questions during installation, contact us at firstname.lastname@example.org.
A note on Python versions
This page recommends the latest version of 32-bit Python 2. You should use this, rather than 64-bit Python or Python 3, unless you have a reason for switching. If you're not which version to use, stick with 32-bit Python 2.
You can also install multiple versions of Python if you want to try out more than one. The command line will use the one that comes first in your Path, and double-clicking on .py files will run whichever one you install last. (To avoid this, uncheck "Register Extensions" while you're running the installer.)
Why Python 2 instead of Python 3?
Python 3 isn't backwards compatible with Python 2, and there are still a lot of libraries that don't work with Python 3. Just as importantly, if you're going to work with any existing Python code, it'll almost certainly be Python 2.
You can use Python 3 if you won't need to work with any existing code, and you know that the libraries you need are available in Python 3.
Why 32-bit instead of 64-bit?
Just like with Python 3, there are a lot of libraries that don't support 64-bit Python.
You should use 64-bit Python if you need to perform very large computations, and you know that the libraries you need have 64-bit versions available.
Is Excel too slow? Speed it up!