Getting Started with Python Programming for Windows Users
Installation of Python
- Download the current production version of Python (3.6.0) from the
Python Download site.
- Double click on the icon of the file that you just downloaded.
- There should be two options - Install Now and Customize installation.
On the same menu screen there should be two options:
- Install launcher for all users (recommended)
- Add Python 3.6 to PATH
Make sure both are checked, and then press Customize Installation.
- The next screen should be titled Optional Features. Make sure all
the boxes are ticked.
- The next screen should be titled Advanced Options. Make sure the
following 4 boxes are ticked:
- Install for all users
- Associate files with Python
- Create shortcuts for installed applications
- Add python to environment variables
- Copy the path listed under Customize install location. It should be
something like:
C:\Program Files (x86)\Python36-32
** You may or may not have the (x86) in the path depending on the
architecture of your PC. Do not worry about it.
- Click next to install
Setting up the Environment
- Starting at My Computer go to the following directory
C:\Python36. In that folder you should see all the Python files.
- Copy that address starting with C: and ending with 35
and close that window.
- For Windows 10 / 8 - Right click on the Windows start button and
Click on System.
- For Windows 7 and below Click on Start. Right Click on My
Computer.
- Click on Properties. Click on Advanced System Settings or
Advanced.
- Click on Environment Variables.
- Under System Variables search for the variable Path.
- Select Path by clicking on it. Click on Edit.
- Scroll all the way to the right of the field called Variable
value using the right arrow.
- Add a semi-colon (;) to the end and paste the path (to the Python
folder) that you previously copied. Click OK.
- Search for CLASSPATH in your list of System Variables. If it
does not exist click on New.
- Enter CLASSPATH for the field Variable name
- Enter .; for the field Variable value. Click OK.
- If the variable CLASSPATH already exists, click Edit.
- In the field Variable value scroll all the way to the left using
the left arrow. Insert .; if that is not there already. Click OK
- Click OK until all the windows close. You have successfully
set up the computing environment.
Writing Your First Python Program
- Create a folder called CS303E on your C:\ drive. You
will be storing all your Python programs in this folder.
- Go to Start and either type Run in the Start Search
box at the bottom or click on Run.
- Type in notepad in the field called Open.
- In Notepad type in the following program exactly as written:
# File: Hello.py
def main():
print ("Hello World!")
main()
- Go to File and click on Save as.
- In the field Save in browse for the C: drive and then
select the folder CS303E.
- For the field File name remove everything that is there
and type in Hello.py.
- In the field Save as type select All Files
- Click on Save. You have just created your first Python program.
Running Your First Program
- Go to Start and click on Run.
- Type cmd in the Open field and click OK.
- A dark window will appear. Type cd C:\ and hit the key Enter.
- If you type dir you will get a listing of all folders in
your C: drive. You should see the folder CS303E that you
created.
- Type cd CS303E and hit Enter. It should take you to the
CS303E folder.
- Type dir and you should see the file Hello.py.
- To run the program, type python Hello.py and hit Enter.
- You should see the line Hello World!
- Congratulations, you have run your first Python program.
Getting Started with Python Programming for Mac Users
Python comes bundled with Mac OS X. But the version that you have is
quite likely an older version.
Download the latest
binary version of Python that runs on your version of Mac OS X and
install it on your system.
If you have an older version of Python on your Mac do NOT uninstall
it. You can have various versions of Python without any problems. To run
the newer version as a separate command edit or create a .bash_profile
in your home directory. You will be in your home directory when you open
your terminal window. Add these two lines in it:
# set the path for Python 3
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
# set up an alias for the Python 3
alias python3='/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6'
Restart your computer. Now if you type python in any Terminal
window the older version will be called upon and if you type python3
you will be using the newer verson. To check the version you are using, run
this command:
python - V
python3 -V
Writing Your First Python Program
- Click on File and then New Finder Window.
- Click on Documents.
- Click on File and then New Folder.
- Call the folder CS303E. You will be storing all class related
programs there.
- Click on Applications and then TextEdit.
- Click on TextEdit on the menu bar and select Preferences.
- Select Plain Text.
- Make sure that the Smart Quote is UNCHECKED.
- Close the empty TextEdit window and create a new one by clicking File
→ New. Now type in the following program, exactly as given:
# File: Hello.py
def main():
print ("Hello World!")
main()
- From the File menu in TextEdit click on Save As.
- In the field Save As: type Hello.py.
- Select Documents and the file folder CS303E.
- Click Save.
Running Your First Program
- Select Applications, then Utilities and Terminal.
- In your Terminal window type ls and Return. It should
give a listing of all the top level folders. You should see the
Documents folder.
- Type cd Documents and hit Return.
- Type ls and hit Return and you should see the folder CS303E.
- Type cd CS303E and hit Return.
- Type ls and hit return and you should see the file
Hello.py.
- To run the program, type python3 Hello.py and hit Return.
- You should see the line Hello World!
- Congratulations, you have run your first Python program.
Starting IDLE on Mac
- In a Terminal window, type python3. This will start
the Python shell. The prompt for that is >>>
- At the Python shell prompt type import idlelib.idle
- This will start the IDLE IDE
Using IDLE on either Windows or Mac
- Start IDLE
- Go to File menu and click on New File
- Type your program in
- Go to File menu and click on Save. Type in filename.py
This will save it as a plain text file, which can be opened in
in any editor you choose (like Notepad or TextEdit).
- To run your program go to Run and click Run Module