![Page 1: UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing Pythoncsev/courses/shared/handouts/old/Installi… · UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing](https://reader033.vdocuments.us/reader033/viewer/2022042309/5ed6d67f126754677f630680/html5/thumbnails/1.jpg)
UNIVERSITYOFMICHIGAN INFORMATICSCharlesSeverance
InstallingPython
IncreasinglyanumberofSchoolofInformationandEECScoursesareusingPythonasaprogramminglanguage.Pythonisviewedasagoodcombinationofeaseofuseandpowerfulcapabilities.Pythonisoftenusedtododatamanipulationandprocessing.Ifyouarenotplanningtobeaprofessional
programmer(i.e.youareabiologistoruserinterfacedesigner)andyouonlyhavetimeorenergytolearnoneprogramminglanguage‐knowonecomputerlanguage–thatlanguageshouldbePython.
ThishandoutcoversgettingPythoninstalledinaMacintosh,WindowsXP,andWindowsVistasystemsandshowsyouhowtorunyourfirstPythonprogram.WewillnotcoverhowtoeditthePythonsourcecode–werecommendJEdit(www.jedit.org)asaprogrammer’seditor.Youwilllikelyendupwith
problemsifyoutrytouseNotepad(Windows)orTextEdit(Macintosh)toedityourPythoncode.YoucanalsousethebuiltinPythoneditor(IDLE)toedityourPythonprograms–thishassomeadvantagesanddisadvantagesaswell–particularlyasyourprogramsgetmoresophisticated.
ThishandoutwillshowyouhowtorunPythonprogramsintheterminalinterfaceineachoftheoperatingsystems.Whilethismightseemalittleclunkyatfirstforfolksusedtopointandclick
interfaces–wefindthatyoufeelmorepowerfulandcapableinthecommandlineinterface–onceyougetusedtoit.
InstallingPythononaMacintoshThegoodnewsisthatPythonisalreadyinstalledonallrecentMacintoshsystems.TocheckwhichversionofPythonyouhave,launchaterminalwindowunderApplications‐>Utilities‐>Terminaland
typethecommand:python–version
![Page 2: UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing Pythoncsev/courses/shared/handouts/old/Installi… · UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing](https://reader033.vdocuments.us/reader033/viewer/2022042309/5ed6d67f126754677f630680/html5/thumbnails/2.jpg)
YouwillbeusingTerminalalot–soyoumightwanttokeepitinyourdockatthebottomofthescreen.TodothisclickontheTerminaliconinthedockandholdforafewseconds–amenuwillpopup–select
KeepinDock–andTerminalwillalwaysbetherewithoneclicktolaunchit.YoumaywanttoupgradetheversionofPythonyouhaveonyourMacintosh–simplygoto
www.python.organddownloadandinstallanewerversion.AfterwardsmakesuretogointoyourterminalprogramandchecktoseethatyouarerunningthecorrectversionofPythonusingtheabovecommand.
MacintoshuserscanskiptheWindowsinstallationandjumptothe“RunningPythonInteractively”section.
InstallingPythononWindowsPythonisverypopularonWindowssystemsbutitdoesnotcomepre‐installedasitdoesonthe
Macintosh.Theinstallationisverysimple–butwehavetoconfiguresomesystemsettingsaftertheinstallation.Goto
http://www.python.org/download/AndsearchfortheWindowsInstaller–downloadtheinstallerandsaveittoyourDesktop.Whenthe
downloadcompletes–simplyclickontheinstallertobegintheinstallationprocess.Duringtheinstallationyoumayseeseveraldialogboxesaskingyoutotrustorapprovetheinstallerto
dosomething.Makesuretosay“yes”or“approve”theseactionssotheinstallationcancontinue.Windowsisjustbeingcautious–thetimetoworryaboutthesepop‐upsiswhen
OncethePythoninstallationiscomplete,youneedtosetituintheWindowsCommandLine.
SettingupPythonForWindowsCommandLineThisstepmakesitpossibletorunPythonfromtheWindowsCommandLine.Itisabitconvoluted‐butyoushouldbeabletofollowthestepsandgetittowork.Ifyouareuncomfortablefollowingthesesteps–getsomehelp–youonlyhavetodothisonceandthenneveragain–soyoudon’thavetoreallylearn
this.Askilledcomputerusercandothisforyouinafewsecondswiththeseinstructions.FirstyouneedtogointotheControlPanelandgettotheSystemPropertiesDialog.Therearedifferent
stepsbetweenVistaandXPtogetthSystemProperties–onceyougettoSystemProperties–thestepsarethesameforbothversionsofWindows.
WindowsVistaInitialSteps:GotoStart‐>ControlPanel(controlpanelisusuallyontherightsideoftheStartpopuponthethirdupfromthebottom).Thenintheupperrightofthecontrolpanelinthe
searcharea,typesystempath‐Vistawillpresentyouwithanoptiontitled“EdittheSystemEnvironmentVariables”.
![Page 3: UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing Pythoncsev/courses/shared/handouts/old/Installi… · UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing](https://reader033.vdocuments.us/reader033/viewer/2022042309/5ed6d67f126754677f630680/html5/thumbnails/3.jpg)
Youwillgetasecuritydialog–thenpressContinueandmoveforwardtoseetheSystemPropertiesdialogbox.
WindowsXPInitialSteps:GotoStart‐>ControlPanel–onceyouareinControlPanel,dependingonwhetheryouareinclassicmodeornot,youmayhavetoSelectPerformanceandMaintenanceandthenclickonSystemtobringuptheSystemPropertiesdialog.
Windows–BothVersions:
PressthebuttonlabeledEnvironmentVariables–inthesectiontitledSystemVariablesscrolldownuntilyoufindtheonecalledPath.
![Page 4: UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing Pythoncsev/courses/shared/handouts/old/Installi… · UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing](https://reader033.vdocuments.us/reader033/viewer/2022042309/5ed6d67f126754677f630680/html5/thumbnails/4.jpg)
AfteryouhaveselectedthePathvariablepresstheEditbutton–itwillbringupthefollowinginterface.
Dothisnextstepcarefully.Putyourcursorinthetextarealabeled“VariableValue”anduseyourrightcursortomovetotheveryendofthestringandthenaddthefollowingtexttotheendofthePath
string.Intheaboveexamplewewanttoaddthetextattheendofthe“Wbem”.YourexistingPathstringmaylookdifferent–allthatmattersisthatyouaddthistextattheendofwhateveristhere.
;C:\Python25Noteifyouareinstallingaversionlaterthan2.5.x,youwillneedtochangethe“25”towhatever
directorythatwasusedtoinstallPython(i.e.thepathmightbeC:\Python26)Whenyouaredone–itshouldlooklikethis.
![Page 5: UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing Pythoncsev/courses/shared/handouts/old/Installi… · UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing](https://reader033.vdocuments.us/reader033/viewer/2022042309/5ed6d67f126754677f630680/html5/thumbnails/5.jpg)
Ifyouareunsureifyouaredoingthisright–justpressCancelabunchoftimesandgetsomehelp.Butifitlooksright(youhaveaddedthe;C:\Python25totheendofthepathstringwithnoextraspaces)–thenpressOKandsavethePathSystemVariable.TheclosetherestoftheDialogboxestoinsurethe
settingsaresaved.Thenchecktoseeifthisworkedbystartingthecommandlineinterface.
WindowsVistaInstructions:PressStart(theroundWindowiconinthelowerright)andinthespacecalledStartSearchtypeinthewordcommand–Vistawillfindthe“CommandPrompt”–selectand
launchtheCommandPrompt.
WindowsXPInstructions:TostartthecommandlineinterfacetoWindowsXP,doStart‐>Run‐>cmd‐>OK–YouwillseeaninterfacethatlooksasfollowsafteryoupressStart‐>Run–simplyentercmdand
pressOK.
WindowsBothVersionsInstructions:
![Page 6: UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing Pythoncsev/courses/shared/handouts/old/Installi… · UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing](https://reader033.vdocuments.us/reader033/viewer/2022042309/5ed6d67f126754677f630680/html5/thumbnails/6.jpg)
Thenbringupthecommandwindowandtype
python‐‐version
Ifallhaswentwell–youshouldseethefollowingscreen.
Ifyoumakeamistake–youcantrytofixthePathvariablemorethanonce–butmakesuretocloseand
re‐openthecommandlineinterfaceeachtimeyouchangethePathvariable–sothecommandlineinterfacereloadsthenewPathVariable.YoucantypethiscommandinthecommandlinetoseethecontentsofthePathvariable:
echo%PATH%
Hopefullyyougetthroughthisstep–orgetsomeonetohelpyouthroughthestepandthenyoucanforgetaboutthisandjustusePythonfromthenon.
UsingPythonIntheWindowsCommandLineInterfaceWindowsVista:TostartthecommandlineinterfacetoWindowsVista,presstheWindowinthelowerrightandinthespacecalledStartSearchtypeinthewordcommand–Vistawillfindthe“Command
Prompt”–selectandlaunchtheCommandPrompt.
![Page 7: UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing Pythoncsev/courses/shared/handouts/old/Installi… · UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing](https://reader033.vdocuments.us/reader033/viewer/2022042309/5ed6d67f126754677f630680/html5/thumbnails/7.jpg)
WindowsXPInstructions:TostartthecommandlineinterfacetoWindowsXP,doStart‐>Run‐>cmd‐
>OK–YouwillseeaninterfacethatlooksasfollowsafteryoupressStart‐>Run–simplyentercmdandpressOK.
OnceyouareinthecommandlineinterfaceinVistaorXP(orMacintoshforthatmatter)–simplytype
python–version
ToseewhatversionofPythonyouarerunning.ThisalsoverifiesthatPythoniscorrectlyinstalled.
![Page 8: UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing Pythoncsev/courses/shared/handouts/old/Installi… · UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing](https://reader033.vdocuments.us/reader033/viewer/2022042309/5ed6d67f126754677f630680/html5/thumbnails/8.jpg)
RunningPythonInteractivelyYoucanusePythonwithoutactuallywritingaprogram–youcanjustrunPythonandgiveitPythoncodeinteractively.Startacommandlineinterface(Terminal,cmd,command–dependingonyouroperatingsystem)andrunPythonwithnoparameters.Youwillseea“>>>”promptwhichindicatesPythonwants
youto“talkPython”toit.Typethefollowingintoyourcommandlineorterminalwindow–yourinputsareinbold.Theexit()
commandterminatesyourinteractivePythonsession.python
Python2.5(r25:51918,Sep192006,08:49:13)[GCC4.0.1(AppleComputer,Inc.build5341)]ondarwinType"help","copyright","credits"or"license"formoreinformation.
>>>print"Hellomynameischuck"Hellomynameischuck>>>print2+2
4>>>exit()
WritingYourFirstPythonProgram(AssumingJEdit)
OpenJEditandtypeinthecodeshownbelow:
Youwillnotethered“floppydisk”iconnexttothefilenamethatindicatesthatthetexthasnotyet
beensavedintoafile.SelectFile‐>SaveAs–thennavigatetoyourDesktop.TheDesktopisdifferentforeachoperatingsystem:
![Page 9: UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing Pythoncsev/courses/shared/handouts/old/Installi… · UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing](https://reader033.vdocuments.us/reader033/viewer/2022042309/5ed6d67f126754677f630680/html5/thumbnails/9.jpg)
Macintosh:/Users/csev/Desktop
WindowsXP:C:\DocumentsandSettings\csev\DesktopWindowsVista:C:\Users\csev\Desktop
Namethefilefirst.pyandpressSavetosavethefile.
AfteryoupressSave,JEditshouldlookasfollows(SeebelowforVistaandXP):
ThenopenthecommandlineinterfaceandswitchtotheDesktopfilesbyusingthecommandcdDesktop
![Page 10: UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing Pythoncsev/courses/shared/handouts/old/Installi… · UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing](https://reader033.vdocuments.us/reader033/viewer/2022042309/5ed6d67f126754677f630680/html5/thumbnails/10.jpg)
Andthentype
pythonfirst.py
Itshouldlookasfollows(Macintosh):
Congratulations–youhaverunyourfirstPythonProgram–giveyourselfapatontheback.
![Page 11: UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing Pythoncsev/courses/shared/handouts/old/Installi… · UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing](https://reader033.vdocuments.us/reader033/viewer/2022042309/5ed6d67f126754677f630680/html5/thumbnails/11.jpg)
IfyouareinWindowsVista,editingandrunningtheprogramwilllookasfollows:
![Page 12: UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing Pythoncsev/courses/shared/handouts/old/Installi… · UNIVERSITY OF MICHIGAN INFORMATICS Charles Severance Installing](https://reader033.vdocuments.us/reader033/viewer/2022042309/5ed6d67f126754677f630680/html5/thumbnails/12.jpg)
IfyouarerunningWindowsXP,editingandrunningtheprogramwilllookasfollows:
ThismaterialisCopyrightCharlesSeveranceunderCreativeCommonsAttribution2.5.