In this tutorial, we are going to
Head across to http://python.org/ and click the Windows Installer link on the homepage.
Once that's downloaded, double-click the .msi to launch the installer.
Just click Next all the way through to accept the default values.
The Path environment variable tells the system where to look for executables. We are going to tell it where to find Python, so that we can run Python from the Windows cmd prompt.
To do this,
Click on Advanced system settings
and then Environment Variables
Find the Path System variable, and click Edit
The variable value field is a list of directories separated by semicolons.
Jump to the end of the list and enter the directory where Python is installed. If you just accepted the defaults when installing Python, this should be C:\Python27\
Click Ok to close the dialog.
In the cmd window that appears, type python and hit enter. If you've set up your path correctly, this will open a Python shell.
Type quit() and hit enter to exit.
We are going to use Notepad++ to create our python source-code files. To do so we need to download a copy of it.
Head over to http://notepad-plus-plus.org/download/v6.5.3.html and download the installer.
Once the installer has finished downloading, run it.
You can just click Next all the way through here to accept the defaults.
If you want to run Notepad++ from the Windows cmd prompt, then add the destination folder to the Windows path environment variable.
This is very similar to the steps in the Set Your Path section (above).
Once Notepad++ has finished installing, open it up.
We are going to create a very simple Python script and then run it.
This serves 2 purposes:
Click on File > New to create a new file in Notepad++
Either type in, or copy and paste the following code:
def main(): print 'hello, world' if __name__ == '__main__': main()
Save the file somewhere easy to find. I'd suggest creating a folder on your Desktop called python_tutorial.
I've given it the filename hello_world.py
By convention, Python source files end with a .py extension.
Navigate to the folder containing your script.
Shift + Right-click in that folder and select Open command window here
This open a cmd window and navigates to the location of the folder for you.
Type in the following command to run your script:
You should see the following output.
Getting your environment set-up can be daunting for python greenhorns.
We've covered a lot of ground. Go grab a coffee. We'll pick up here in the next tutorial.