Installing)Python) - Northwestern University

Installing Python

The following directions are an example for specific operating systems and versions; they work for the stated specs; you might have to alter them as needed for your circumstances.

Here is a good resource explaining the main differences between Python 2.7 and 3.4: nbviewer.github/rasbt/python_reference/blob/master/tutorials/key_differences_betw een_python_2_and_3.pynb

One critical property of Python-- it does NOT use brackets { }.

Rather, it uses indenting to designate code offsets.

The spacing is critical.

Both MAC and Windows install come with an editor called IDLE which will mostly handle this for you.

Just be careful that code lines up if it is not compiling.

An "indent" is 4 spaces.

Another property-- the "main" statement is not necessary.

We will see how to use one in the template for Project 1.

I purposely take you through a slightly longer procedure than necessary to write the first Hello World program.

This is a baseline process, and you can always come back to it to write files.

It is possible to write python programs using text files, but this is furtively not recommended-- the indenting requirement becomes almost impossible (whereas IDLE tries to handle it for you). This process involves calling python from a command line prompt.

The reason is that a terminal will print output and then give you another prompt.

However, if you just run a python file, it will print output and then close the output screen immediately upon completing.

This can be interrupted in a slightly unnatural way with input() command (you don't actually want input, just use it as a pause).

You are encouraged to explore this technique via internet search.

For MAC

The following operations were performed on Mac OS X version 10.9.4

Navigate to: download/releases/2.7.8/

Download "Mac OS X 32--bit i386/PPC Installer (2.7.8) for Mac OS X 10.5 and later [2] (sig)"

You can open the download using either the `Download Arrow' in the upper right corner of Safari; or I was also able to find it as a Device within Finder; strangely, I did not find it in my Downloads Folder itself.

Open Python.mpkg

If your Mac blocks it allowing only applications from "Mac App Store + Identified Developers Only"; ------ Click on the Apple logo upper left corner and select System Preferences from the drop down menu ------ Security & Privacy ------ General ------ Change to from "Anywhere"; you might have to click a lock in the bottom left corner and put in your system user password to make this change; you can change this back afterwards ------ Again open Python.mpkg

Click through the default install process

In Finder, go to Applications and open the new Python 2.7 folder; open Idle which gives you an IDLE terminal; however we want a python file so at the top of the screen, File --> New File

In the Python file that opens, type the following exactly:

print ("hello world!")

and save in documents as helloworld.py (it will probably not let you save it in the Python 2.7 folder) ** within documents, you might want to save it in a sub--folder for projects for this class rather than in the general documents folder

Open a Terminal (should be in Applications, if not there, search your entire mac for "terminal")

Type the following commands exactly:

cd ..

cd ls

cd ..

cd Applications

[do not type this instruction: or,

otherwise navigate to where your Python download folder was

saved]

cd `Python 2.7'

python /users/[insert your user name, which you can find

listed above in the terminal window in response to your "cd ls"

command]/documents/helloworld.py

"hello world!" should print in the terminal in response to the last command running python on the given argument (path/file)

of course, if you originally saved the helloworld.py file in a sub--directory of documents, then the path to the file should reflect this as /documents/[extra path]/helloworld.py

***** To edit a previously saved (and closed file), you have to "right--click" on it and choose "Edit with IDLE"

For Windows:

The following operations were performed on Windows 7 Home Premium

Navigate to: download/releases/2.7.8/

Download "Windows x86 MSI Installer (2.7.8)"

Save to wherever you want (probably downloads), this is just the download of the installer and afterwards, you will have the opportunity to "Open Folder" directly

Open Folder and double--click Python--2.7.8 and Run

Click through install, probably install it as C:\Program Files\Python27

Finish Install and navigate to Python27 folder (even if you saved it in "Program Files" it might end up in "Program Files (x86)"

Start Idle by further navigating to Lib\idlelib\ folder and running idle (Windows Batch Program, not the PY or PYW file types)

An IDLE terminal should start.

Open a new file with File --> New File

In the Python file that opens, type the following exactly:

print ("hello world!")

and save in My Documents as helloworld.py (it will probably not let you save it in the Python27 folder) ** within My Documents, you might want to save it in a sub--folder for projects for this class rather than in the general My Documents folder

Open a command prompt (start menu, in the search field enter "cmd") Type the following commands exactly:

cd ..

cd ..

cd Program Files (x86)

[do not type this instruction:

or, otherwise navigate to where your Python download folder

was saved]

cd `Python27'

python /users/[insert your user name, which you can find by

opening a Windows Explorer file and find in C:\Users\]/my

documents/helloworld.py

"hello world!" should print in the terminal in response to the last command running python on the given argument (path/file)

of course, if you originally saved the helloworld.py file in a sub--directory of My Documents, then the path to the file should reflect this as /my documents/[extra path]/helloworld.py

***** To edit a previously saved (and closed file), you can right--click on it and choose "Edit with IDLE"

***** If this option is not available when you right--click, you will have to re--open IDLE the hard way (in Windows Explorer, go to Python27\Lib\idlelib and click on the idle Windows Batch Application, then File --> Open)

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download