Python on Windows: Difference between revisions

From OpenHatch wiki
Content added Content deleted
imported>Paulproteus
imported>Jesstess
No edit summary
 
(24 intermediate revisions by 6 users not shown)
Line 1: Line 1:
== Download and install Python ==

If you believe you already have Python installed, please let a staff member know before completing these steps.

<ol>
<ol>
<li>Go to http://python.org/download/ and download the latest version of Python 2.7 (2.7.1 at the time of writing). Unless you know otherwise, get the "Windows Installer" version, and not the "Windows X86-64 Installer" version.</li>
<li>Click http://python.org/ftp/python/2.7.1/python-2.7.1.msi and choose "run" if you have the option to. Otherwise, save it to your Desktop, then minimize windows to see your desktop, and double click on it to start the installer. Follow the installer instructions to completion.</li>
<li><b>Open a command prompt (we will be doing this multiple times, so make a note of how to do this!)</b>:
<li>Start up a command prompt by clicking on the Start menu, clicking the "Run..." option, typing "cmd", and hitting enter. If you are using Windows Vista, you should click on the Start menu, type "cmd" into the Search field directly above the Start menu button, and click on "cmd" in the search results above the Search field.</li>
* On Windows Vista or Windows 7: click on the Start menu (the Windows logo in the lower left of the screen), type <code>cmd</code> into the Search field directly above the Start menu button, and click on "cmd" in the search results above the Search field.
<li>Test your Python install by typing
* On Windows XP: click on the Start menu (the Windows logo in the lower left of the screen), click on "Run...", type <code>cmd</code> into the text box, and hit enter.
<br />
You now have what's called a command prompt. This command prompt is another way of navigating your computer and running programs -- just textually instead of graphically. We are going to be running Python and Python scripts from this command prompt.
</li>
<li>At this <code>C:\</code> prompt that appears, test your Python install by typing


<pre>
<pre>
Line 14: Line 23:
>>>
>>>
</pre>
</pre>

You just started Python! The <code>>>></code> indicates that you are at a new type of prompt -- a Python prompt. The command prompt let's you navigate your computer and run programs, and the Python prompt lets you write and run Python code interactively.

</li>
</li>
<li>To exit the Python prompt, type
<li>To exit the Python prompt, type


<pre>
exit()
exit()
</pre>


and press Enter. This will take you back to the Windows command prompt.</li>
and press Enter. This will take you back to the Windows command prompt (the <code>C:\</code> you saw earlier).</li>
</ol>
</ol>


== Required step: Put Python on the PATH ==
== Put Python on the PATH ==


You might have noticed that you typed a directory name above when launching Python. In this step, you will reconfigure your computer to put Python on the system PATH so that you can run it without typing the ''Python27'' directory name.
You might have noticed that you typed a "full path" to the Python application above when launching Python (<code>python.exe</code> is the application, but we typed <code>\Python27\python.exe</code>). In this step, you will configure your computer so that you can run Python without typing the ''Python27'' directory name.


=== Get to System Properties ===
'''This will take about 5 extra minutes''', and it is ''essential'' to an easy life using Python down the road.


# Open up "My Computer" by clicking on the Start menu or the Windows logo in the lower-left hand corner, and navigate to "My Computer" (for Windows XP) or "Computer" (For Vista and Windows 7).
=== For Windows 7 ===
# ''Right-click'' on the empty space in the window, and choose ''Properties''.


==== If you're using XP ====
(Note: These steps are based on a '''[http://www.youtube.com/watch?v=g9JvseacxPY video that we recommend you watch]'''.)


A window labeled "System Properties" will pop up.
# Click the Windows logo in the bottom left...

#* Click "Computer", and wait for a window to appear with the drives in your computer
# Click the "Advanced" tab.
# ''Right-click'' on the empty space in the window, and choose ''Properties'

#* A window labeled "View basic information about your computer" should appear
==== If you're not using XP ====
# In the new window, click "Advanced system settings"
A window labeled "View basic information about your computer" will appear.
#* A window should appear whose title is "System Properties"

#* Make sure you are in the tab labeled "Advanced"
# In this window, click "Advanced system settings"
# Click the button labeled "Environment Variables". A window labeled "Environment Variables" should appear.

A window with the title "System Properties" will appear.

=== Edit the Path ===

# Within System Properties, make sure you are in the tab labeled "Advanced".
# Click the button labeled "Environment Variables".
#* A window labeled "Environment Variables" will appear.
# In this window, the screen is split between "User variables" and "System variables". Within "System variables", scroll down and find the one labeled '''Path'''. Click the "Edit..." button.
# In this window, the screen is split between "User variables" and "System variables". Within "System variables", scroll down and find the one labeled '''Path'''. Click the "Edit..." button.
#* A window with the "Variable name" and the "Variable value" should appear.
#* A window with the "Variable name" and the "Variable value" should appear. The "Variable value" will already have some text in it; click in the box to unhighlight it (we don't want to accidentally delete that text).
# In the "Variable value", scroll to the end. Add this text, and hit OK. Make sure to include the semicolon at the start! <pre>;c:/python27/;c:/python27/scripts</pre>
# In the "Variable value" box, scroll to the end. Add the following text, and hit OK. Make sure to include the semicolon at the start! <pre>;c:\python27\;c:\python27\scripts</pre>
# Hit "OK" to close out the system properties changes.
# Hit "OK" to close out the system properties changes.
# Test it:
# Test your change:
## Open up a <b>new</b> command prompt: you do this the same way you did above when installing python. This needs to be a new command prompt because the changes you just made didn't take affect in prompts that were already open.
#* Open up a command prompt
#* Type just "python" into the command prompt
## Type <code>python</code> into the command prompt to start Python
#* Notice that you now get a Python interpreter.
## Notice that you now get a Python interpreter, indicated by the change to a <code>>>></code> prompt.
## Exit the Python prompt by typing <pre>exit()</pre> and hitting enter. Now you're back at the Windows command prompt (<code>C:\</code>).

== Success! ==

You have Python installed and configured.

[[Boston Python workshop 2/Friday setup|&laquo; Back to the Friday setup page]]

Latest revision as of 17:55, 13 May 2011

Download and install Python

If you believe you already have Python installed, please let a staff member know before completing these steps.

  1. Click http://python.org/ftp/python/2.7.1/python-2.7.1.msi and choose "run" if you have the option to. Otherwise, save it to your Desktop, then minimize windows to see your desktop, and double click on it to start the installer. Follow the installer instructions to completion.
  2. Open a command prompt (we will be doing this multiple times, so make a note of how to do this!):
    • On Windows Vista or Windows 7: click on the Start menu (the Windows logo in the lower left of the screen), type cmd into the Search field directly above the Start menu button, and click on "cmd" in the search results above the Search field.
    • On Windows XP: click on the Start menu (the Windows logo in the lower left of the screen), click on "Run...", type cmd into the text box, and hit enter.

    You now have what's called a command prompt. This command prompt is another way of navigating your computer and running programs -- just textually instead of graphically. We are going to be running Python and Python scripts from this command prompt.
  3. At this C:\ prompt that appears, test your Python install by typing
    \Python27\python.exe
    

    and hitting enter. You should see something like

    Python 2.7.1 (r271:86832, ...) on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    

    You just started Python! The >>> indicates that you are at a new type of prompt -- a Python prompt. The command prompt let's you navigate your computer and run programs, and the Python prompt lets you write and run Python code interactively.

  4. To exit the Python prompt, type
    exit()
    
    and press Enter. This will take you back to the Windows command prompt (the C:\ you saw earlier).

Put Python on the PATH

You might have noticed that you typed a "full path" to the Python application above when launching Python (python.exe is the application, but we typed \Python27\python.exe). In this step, you will configure your computer so that you can run Python without typing the Python27 directory name.

Get to System Properties

  1. Open up "My Computer" by clicking on the Start menu or the Windows logo in the lower-left hand corner, and navigate to "My Computer" (for Windows XP) or "Computer" (For Vista and Windows 7).
  2. Right-click on the empty space in the window, and choose Properties.

If you're using XP

A window labeled "System Properties" will pop up.

  1. Click the "Advanced" tab.

If you're not using XP

A window labeled "View basic information about your computer" will appear.

  1. In this window, click "Advanced system settings"

A window with the title "System Properties" will appear.

Edit the Path

  1. Within System Properties, make sure you are in the tab labeled "Advanced".
  2. Click the button labeled "Environment Variables".
    • A window labeled "Environment Variables" will appear.
  3. In this window, the screen is split between "User variables" and "System variables". Within "System variables", scroll down and find the one labeled Path. Click the "Edit..." button.
    • A window with the "Variable name" and the "Variable value" should appear. The "Variable value" will already have some text in it; click in the box to unhighlight it (we don't want to accidentally delete that text).
  4. In the "Variable value" box, scroll to the end. Add the following text, and hit OK. Make sure to include the semicolon at the start!
    ;c:\python27\;c:\python27\scripts
  5. Hit "OK" to close out the system properties changes.
  6. Test your change:
    1. Open up a new command prompt: you do this the same way you did above when installing python. This needs to be a new command prompt because the changes you just made didn't take affect in prompts that were already open.
    2. Type python into the command prompt to start Python
    3. Notice that you now get a Python interpreter, indicated by the change to a >>> prompt.
    4. Exit the Python prompt by typing
      exit()
      and hitting enter. Now you're back at the Windows command prompt (C:\).

Success!

You have Python installed and configured.

« Back to the Friday setup page