O'Reilly Introduction to Python/Section 1/Linux set up Python: Difference between revisions

From OpenHatch wiki
Content added Content deleted
imported>Jesstess
No edit summary
imported>Jesstess
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
[[File:Python-logo.png|300px]]
[[File:Python-logo.png|300px]]


Lucky for us, Linux comes with Python installed! All we need to do is make sure we have an appropriate version of Python installed and make sure we can start a Terminal and run Python from the command line.
In this section, we are going to check which version of Python is installed, and possibly install a newer version.

__TOC__

== Check your Python installation ==


<ol>
<ol>
Line 7: Line 11:


<br />
<br />
This Terminal contains something 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.
This Terminal 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 Terminal.
</li>
</li>
<li>Test your Python install at the command prompt. Type
<li>Test your Python installation at the Terminal prompt by typing


<pre>
<pre>
Line 15: Line 19:
</pre>
</pre>


and hit enter. You should see something like
and pressing Enter. You should see something like
<pre>
<pre>
Python 2.7.5 (r252:60911, Jan 24 2011, 17:44:40)
Python 3.4.1 (v3.4.1:d047928ae3f6, May 13 2013, 12:45:22)
[GCC 4.3.2] on linux2
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Type "help", "copyright", "credits" or "license" for more information.
Line 24: Line 28:
</li>
</li>


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

* If the Python version number (2.7.5 in the example above) is not a number between 2.4 and 2.7 (ignoring the number after the second dot), tell a staff member.
</li>
</li>
<li>To exit the Python prompt, type
<li>Exit the Python prompt by typing


<pre>
<pre>
Line 34: Line 36:
</pre>
</pre>


and press Enter. This will take you back to the Linux command prompt.</li>
and pressing Enter. This will take you back to the Linux Terminal prompt.</li>
</ol>
</ol>


<b>If your Python version started with a 3</b>, you are done with this section; please [[O'Reilly Introduction to Python/Section 1|&laquo; return to the Section 1 main page]]

<b>If your Python version started with a 2</b>, you may have a version of Python 3 installed, just not as the default Python. Type

<pre>
python3
</pre>

at a Terminal prompt.

If this starts Python, you have a version of Python 3 installed, just not as the default Python. Please use the command <b>python3</b> instead of <b>python</b> to start Python for the rest of this course.

If you have no version of Python 3 installed, we'll need to install it. Please continue to the instructions in the next section.

== Install Python ==

Please install Python 3.4 using your package manager, or from source using the source release [https://www.python.org/downloads/release/python-341/ here].

Please use the command <b>python3</b> instead of <b>python</b> to start Python for the rest of this course.


== Success! ==
== Success! ==
Line 44: Line 65:
[[File:Champagne.png|100px]][[File:Party.png|125px]]
[[File:Champagne.png|100px]][[File:Party.png|125px]]


[[O'Reilly Introduction to Python/Section 1|&laquo; Back to the Unit 1 main page]]
[[O'Reilly Introduction to Python/Section 1|&laquo; Back to the Section 1 main page]]

Latest revision as of 02:45, 27 May 2014

In this section, we are going to check which version of Python is installed, and possibly install a newer version.

Check your Python installation

  1. Start up a Terminal. You can find the Terminal application at Applications/Accessories/Terminal, or it may already be on your menu bar.

    This Terminal 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 Terminal.
  2. Test your Python installation at the Terminal prompt by typing
    python
    

    and pressing Enter. You should see something like

    Python 3.4.1 (v3.4.1:d047928ae3f6, May 13 2013, 12:45:22) 
    [GCC 4.3.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    
  3. You just started Python! The >>> indicates that you are at a new type of prompt -- a Python prompt. The Terminal prompt lets you navigate your computer and run programs, and the Python prompt lets you write and run Python code interactively.
  4. Exit the Python prompt by typing
    exit()
    
    and pressing Enter. This will take you back to the Linux Terminal prompt.

If your Python version started with a 3, you are done with this section; please « return to the Section 1 main page

If your Python version started with a 2, you may have a version of Python 3 installed, just not as the default Python. Type

python3

at a Terminal prompt.

If this starts Python, you have a version of Python 3 installed, just not as the default Python. Please use the command python3 instead of python to start Python for the rest of this course.

If you have no version of Python 3 installed, we'll need to install it. Please continue to the instructions in the next section.

Install Python

Please install Python 3.4 using your package manager, or from source using the source release here.

Please use the command python3 instead of python to start Python for the rest of this course.

Success!

You have tested your Python installation.

« Back to the Section 1 main page