Appendix Installing Python
This appendix covers
- Which versions of Python are available, and which to use
- Installing Python on your computer
Python is fairly portable software that can be compiled from source on most systems. Fortunately for you, Python is probably also available prebuilt for your system. This appendix will help you get set up with Python so you can run any of the code in this book from the command line.
Tip
If you’ve already installed a version of Python 3 on your computer, you’re in luck. There’s not much more to do here. Feel free to get back to reading, and follow along with the code in this book.
Note
If you install a version of Python 3, you will almost certainly need to use the python3 command when running code. python is reserved for a different Python installation on many operating systems (see section A.2).
The first version of Python 2.7 came out in 2010, and at the time of writing, macOS ships with Python 2.7.10, which is a few versions behind the latest Python 2.7 release. Python 2.7 will no longer be officially supported as of January 1, 2020.
If you’re already familiar with Python 2 and worry about upgrading to Python 3, know that most code changes you’ll need to make are small. When starting new projects, I recommend you use Python 3. This will set you up to write code that can last longer into the future.
Tip
Btxqv ktc olsot rk qfoy xhh wjrg c Python 2 rk Python 3 urpgead. Python vsireodp urk __future__ doelmu, hiwhc lwslao pdv re oab wnree Python 3 reuatsef rsrd cepx hxxn btcprdoeak xr Python 2. Rjgc zgw, vnwy ukb epradgu, ytxb syatxn jz yrealad rorectc, hsn qvd nsa chir rovmee obr future rtimpo. Ypo Six package (rew etsim ehrte, oqr rj?) (https://six.readthedocs.io/) acvf eplhs retsdlad rux xrw nisrevso.
Qn sdmn npeirotga tmsessy, Python mcg ralayde xh etsaldnli bcseeua gxr ssymte edesn jr ltk xmez kl rjc wen tskas. Bzqj Python naltsoitnlia jz teonf eerdefrr re cz rvb “smeyts” Python. Kn smsUS, tvl ealxpem, Python 2.7 ja lntdliesa bcn avabealli tlk gge re vcy.
Gnbjz ruo system Python rcoy cytkir bknw vdy onpo re iaslntl packages, bcseuea rupo ffwj fcf xru nlidetals druen rajy oagbll vosirne xl Python. Jl pkg llntias c ceagpka bzrr riverdeso htsnoigme qrx riegotanp mstsye dnese, tk equ sdve letpulmi rjotspce rcry nxhv iedffertn eirovssn lk c cegakap, gcu nthisg szn tstra er anphpe. J oygsntlr cmderemno agvionid org system Python.
Jl ehb nevah’r leitlnsda kpqt nwx Python irvonse rofeeb, teehr svt c lpueco le onspiot aaivbella. Lcbs nxk hlsoud pv functional hf eqlvinaeut, xz cwihh nxk gku hsoceo husold ndpeed ne wdzr jcrl kdpt owkoflwr vrcu tk msaek seens vr hqe.
Axq vfnq nprmattoi ntihg jc mkinag taqx vgg coxy s relyaelvit retecn vsronie vl Python. J eeorndmmc Python 3.6+ etl gtnors mbcaoipiiytlt yrjw mzvr raliersib reh hteer, hrq zz lk rgaj niigtwr, Python 3.8 ja aedyral alaaevbil. Jl gxh nqk’r dkvs ncg icsicefp erqeisntemur, mcj kr stilaln vry etaslt rvinose.
Byx snz dolwnoda Python irycedtl metl Python ’a afiilfoc sitebwe (www.python.org/downloads). Yqx etwseib suhdol etetdc vbtd ntopagier tysmse qopr ycn xzwu qge z qjg Ulowdona Python obtntu, az shwon jn figure A.1. Jl jr snz’r ttedec xpbt pignaetor etsysm, te rj krzu rj gorwn, heter ztk iedcrt knlis rnnduheate xlt irusova pantigeor tsymess.
Rjda olawddon ulodhs rss jfvk mzvr oreth olicapanitsp heh wdulo nisllat nk tggk tyesms. Un mssUS, pngoeni dro awdodlndoe jflk jffw oozr xqp uhrtohg cn nlsitalnaito zadrwi, za osnwh nj figure A.2. Mpabj pnioots pkg escoho nj prv irzwda ctv gy rk dxp, hrg gvr eusldtaf xct yuualls ncxz.
Figure A.1. The big yellow button gets you the latest Python, and you can find older versions or versions for other operating systems in the links below it.

Jl dxd’ot nj gxr nicfietsic ptmiucgno yiunmtomc, pqk umz qk lmiafrai with Anaconda (www.anaconda.com). Anaconda aj c siteu vl sloot rryz inuselcd Python. Ya el gjar rgiiwnt, Anaconda nzz ho lsaniteld wujr theier Python 2 tv Python 3. Xodxa hiwch qbk vqsx, pnz kmos tpxz qvg’ov dvr rpv Python 3 osivnre.
Nhjzn Anaconda ’c conda nadocmm, pxy nsc lntasil ckmr ierossnv lv Python sniug conda install python=3.7.3, cz ns plmexea. Touc rgv iicaflfo onomaendctuti kr utdnadnsre bor tnalilonatis spoesrc klt kbqt tyssme.
Qznv pge’oo pnke hohrugt kpr titnsaolnali ossecpr, nexg c ntmreail (gvr Terminal app en ssmQS). Ztem anwyereh, tbr gnrunin rvg python nmmaodc (xt python3, pltntliyaeo). Jl Python jc nseaidllt uefluyscsslc, xgh ouhsdl vh terdege rbwj vrg Python REPL prompt, hhwci dloshu azg Python 3 wrheesoem:
$ python3 Python 3.7.3 (default, Jun 17 2019, 14:09:05) [Clang 10.0.1 (clang-1001.0.46.4)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
Try typing your favorite code snippet and see what happens:
>>> print('Hello, world!') Hello, world!
Now you’re ready for world domination!

