Repository navigation
Expand file tree
/
Copy pathpython_for_mac.html
More file actions
364 lines (258 loc) · 18.5 KB
/
Copy pathpython_for_mac.html
File metadata and controls
364 lines (258 loc) · 18.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Setting up OS-X for Python — Python 210 6.0 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" style="background: #4b2e83" >
<a href="../../index.html">
<img src="../../_static/UWPCE_logo_full.png" class="logo" alt="Logo"/>
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../topics/index.html">Introduction to Python</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../MultipleInheritance.html">15.1.1. Multiple Inheritance</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Python 210</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content style-external-links">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> »</li>
<li>Setting up OS-X for Python</li>
<li class="wy-breadcrumbs-aside">
<a href="../../_sources/modules/dev_environment/python_for_mac.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="setting-up-os-x-for-python">
<span id="python-for-mac"></span><h1>Setting up OS-X for Python<a class="headerlink" href="#setting-up-os-x-for-python" title="Permalink to this headline">¶</a></h1>
<div class="section" id="getting-the-tools">
<h2>Getting The Tools<a class="headerlink" href="#getting-the-tools" title="Permalink to this headline">¶</a></h2>
<p>OS-X comes with Python out of the box, but not the full setup you’ll need for development or this class. It also doesn’t have the latest version(s), and no version of Python 3.</p>
<p>So we recommend installing a new version.</p>
<p><strong>Note</strong>:</p>
<p>If you use <code class="docutils literal notranslate"><span class="pre">macports</span></code> or <code class="docutils literal notranslate"><span class="pre">homebrew</span></code> to manage *nix software on your machine, feel free to use those for <code class="docutils literal notranslate"><span class="pre">python</span></code>, <code class="docutils literal notranslate"><span class="pre">git</span></code>, etc, as well. But make sure you have Python 3.7.*</p>
<p>If not, then read on.</p>
<div class="section" id="terminal">
<h3>Terminal<a class="headerlink" href="#terminal" title="Permalink to this headline">¶</a></h3>
<p>You will need a command line terminal. The built-in “terminal” application works fine. Find it in:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">/</span><span class="n">Applications</span><span class="o">/</span><span class="n">Utilities</span><span class="o">/</span><span class="n">Terminal</span>
</pre></div>
</div>
<p>Drag it to the dock to easily access.</p>
</div>
<div class="section" id="python">
<h3>Python<a class="headerlink" href="#python" title="Permalink to this headline">¶</a></h3>
<p>While OS-X does provide Python out of the box, it tends not to have the
latest version, and you really don’t want to mess with the system
installation. So we recommend installing an independent installation from
<code class="docutils literal notranslate"><span class="pre">python.org</span></code>:</p>
<p>Download the latest realease of Python (currently 3.7.0) installer from Python.org:</p>
<p><a class="reference external" href="https://www.python.org/downloads/">https://www.python.org/downloads/</a></p>
<p>Double click the installer and follow the prompts. The defaults are your best bet. Simple as that.</p>
<p>Oddly, this does NOT install a <code class="docutils literal notranslate"><span class="pre">python</span></code> command, but rather a <code class="docutils literal notranslate"><span class="pre">python3</span></code> command. If you want to be able to simply type <code class="docutils literal notranslate"><span class="pre">python</span></code> and get python3, then you can add a symlink to the install. Type this at a terminal prompt:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ <span class="nb">cd</span> /Library/Frameworks/Python.framework/Versions/3.7/bin
$ ln -s python3.7 python
</pre></div>
</div>
<p>Or an add an alias in your shell by adding the following line:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">alias</span> <span class="n">python</span><span class="o">=</span><span class="s1">'python3'</span>
</pre></div>
</div>
<p>to your <code class="docutils literal notranslate"><span class="pre">.bash_profile</span></code> file.</p>
<p>Once you have done that, you should be able to type <code class="docutils literal notranslate"><span class="pre">python</span></code> at the command prompt, and get something like:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ python
Python <span class="m">3</span>.7.0 <span class="o">(</span>v3.7.0:1bf9cc5093, Jun <span class="m">26</span> <span class="m">2018</span>, <span class="m">23</span>:26:24<span class="o">)</span>
<span class="o">[</span>Clang <span class="m">6</span>.0 <span class="o">(</span>clang-600.0.57<span class="o">)]</span> on darwin
Type <span class="s2">"help"</span>, <span class="s2">"copyright"</span>, <span class="s2">"credits"</span> or <span class="s2">"license"</span> <span class="k">for</span> more information.
>>>
</pre></div>
</div>
<p>This is the Python interpreter.</p>
<p>Type <code class="docutils literal notranslate"><span class="pre">ctrl+D</span></code> to get out (or <code class="docutils literal notranslate"><span class="pre">exit()</span></code>)</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If all this is confusing to you – take heart – you will get used it it. And in the meantime, you can simply type <code class="docutils literal notranslate"><span class="pre">python3</span></code> when you want to run python.</p>
</div>
</div>
<div class="section" id="pip">
<h3>pip<a class="headerlink" href="#pip" title="Permalink to this headline">¶</a></h3>
<p><code class="docutils literal notranslate"><span class="pre">pip</span></code> is the Python package installer. It is updated more frequently than Python itself, so once you have Python, you want to get the latest version of pip working:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ python3 -m ensurepip --upgrade
</pre></div>
</div>
<p>[<code class="docutils literal notranslate"><span class="pre">python</span></code> may work too, if you set things up correctly above, but <code class="docutils literal notranslate"><span class="pre">python3</span></code> should always work.]</p>
<p>It should download and install the latest <code class="docutils literal notranslate"><span class="pre">pip</span></code>. Or let you know that you already have it.</p>
<p>You can now use pip to install other packages. The first thing you may want to do is update pip itself:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ python3 -m pip install --upgrade pip
</pre></div>
</div>
</div>
<div class="section" id="using-pip">
<h3>Using pip:<a class="headerlink" href="#using-pip" title="Permalink to this headline">¶</a></h3>
<p>To use pip to install a package, you invoke it with this command:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python3</span> <span class="o">-</span><span class="n">m</span> <span class="n">pip</span> <span class="n">install</span> <span class="n">the_name_of_the_package</span>
</pre></div>
</div>
<p>Where <code class="docutils literal notranslate"><span class="pre">python3</span></code> is the command you use to invoke the Python you want to use.</p>
<p><strong>NOTE:</strong> You will frequently see advice to use pip like so:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pip install something_or_other
</pre></div>
</div>
<p>This often works, but also can invoke the <em>wrong</em> version of pip. This command:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ python3 -m pip install something_or_other
</pre></div>
</div>
<p>calls Python, and tells it to run the <code class="docutils literal notranslate"><span class="pre">pip</span></code> module. It is exactly the same as calling pip directly, except that you are assured that you are getting the version of pip connected the version of Python that you are running.</p>
</div>
<div class="section" id="ipython">
<h3>iPython<a class="headerlink" href="#ipython" title="Permalink to this headline">¶</a></h3>
<p>One package we are going to use in the program from the beginning is <code class="docutils literal notranslate"><span class="pre">iPython</span></code>. You can install it with <code class="docutils literal notranslate"><span class="pre">pip</span></code> like so:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ python3 -m pip install ipython
</pre></div>
</div>
<p>(It will install a LOT…).</p>
<p>Now you should now be able to run <code class="docutils literal notranslate"><span class="pre">iPython</span></code>:</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="go">$ ipython</span>
<span class="go">Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24)</span>
<span class="go">Type 'copyright', 'credits' or 'license' for more information</span>
<span class="go">IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.</span>
<span class="gp">In [1]:</span>
</pre></div>
</div>
<p>Which you can also get out of with <code class="docutils literal notranslate"><span class="pre">ctrl+D</span></code> or <code class="docutils literal notranslate"><span class="pre">exit()</span></code></p>
</div>
<div class="section" id="git">
<h3>git<a class="headerlink" href="#git" title="Permalink to this headline">¶</a></h3>
<p>git is a source code version control system. It is not strictly related to Python, but it (or a similar system) is a critical tool for software development in general, and it is very widely used in the Python community. We will be using it, along with the gitHub service, in the program to hand in assignments and support code review.</p>
<p>You need a git client. The gitHub GUI client may be nice; I honestly don’t know. However, we will be using the command line client in class.</p>
<p>There are a couple of options for a command line client.</p>
<p>This option is a big download and install, but has everything you need out of the box:</p>
<p><a class="reference external" href="http://sourceforge.net/projects/git-osx-installer/">http://sourceforge.net/projects/git-osx-installer/</a></p>
<p>NOTE: if you get a warning like:</p>
<p>“… can’t be opened because it is from an untrusted developer”</p>
<p>you’ll need to go to system preferences:</p>
<blockquote>
<div><p>“Security and Privacy”</p>
<p>Depending on the OS-X version, you will need to check the box saying “Open Anyway,” or perhaps the box saying you can install untrusted packages.</p>
</div></blockquote>
<p>This option works great, but you need the XCode command line tools to run it:</p>
<p><a class="reference external" href="http://git-scm.com/download/mac">http://git-scm.com/download/mac</a></p>
<p>You can get XCode from the Apple App Store. If you try running “git” on the command line after installing, it should send you there. Warning: XCode is a BIG download. Once installed, run it so it can initialize itself.</p>
<p>After either of these is installed, the <code class="docutils literal notranslate"><span class="pre">git</span></code> command should work:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ git --version
git version <span class="m">2</span>.11.0 <span class="o">(</span>Apple Git-81<span class="o">)</span>
</pre></div>
</div>
</div>
<div class="section" id="testing-it-out">
<h3>Testing it out<a class="headerlink" href="#testing-it-out" title="Permalink to this headline">¶</a></h3>
<dl class="simple">
<dt>To be ready for the program, you need to have, all available from the command line:</dt><dd><ul class="simple">
<li><p>python</p></li>
<li><p>pip</p></li>
<li><p>iPython</p></li>
<li><p>git</p></li>
</ul>
</dd>
</dl>
<p>To try it out, you should be able to run all of the following commands, and get something like the results shown:</p>
<p>(recall that you can get out of the Python or iPython command lines with <code class="docutils literal notranslate"><span class="pre">ctrl+D</span></code>)</p>
<div class="section" id="for-python">
<h4>For Python:<a class="headerlink" href="#for-python" title="Permalink to this headline">¶</a></h4>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ python3
Python <span class="m">3</span>.7.0 <span class="o">(</span>v3.7.0:1bf9cc5093, Jun <span class="m">26</span> <span class="m">2018</span>, <span class="m">23</span>:26:24<span class="o">)</span>
<span class="o">[</span>Clang <span class="m">6</span>.0 <span class="o">(</span>clang-600.0.57<span class="o">)]</span> on darwin
Type <span class="s2">"help"</span>, <span class="s2">"copyright"</span>, <span class="s2">"credits"</span> or <span class="s2">"license"</span> <span class="k">for</span> more information.
>>>
</pre></div>
</div>
</div>
<div class="section" id="for-ipython">
<h4>For iPython:<a class="headerlink" href="#for-ipython" title="Permalink to this headline">¶</a></h4>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ ipython
Python <span class="m">3</span>.7.0 <span class="o">(</span>v3.7.0:1bf9cc5093, Jun <span class="m">26</span> <span class="m">2018</span>, <span class="m">23</span>:26:24<span class="o">)</span>
Type <span class="s1">'copyright'</span>, <span class="s1">'credits'</span> or <span class="s1">'license'</span> <span class="k">for</span> more information
IPython <span class="m">6</span>.5.0 -- An enhanced Interactive Python. Type <span class="s1">'?'</span> <span class="k">for</span> help.
</pre></div>
</div>
</div>
<div class="section" id="for-pip">
<h4>For pip:<a class="headerlink" href="#for-pip" title="Permalink to this headline">¶</a></h4>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ python3 -m pip --version
pip <span class="m">18</span>.0 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip <span class="o">(</span>python <span class="m">3</span>.7<span class="o">)</span>
</pre></div>
</div>
<p>Note that when you ask pip for <code class="docutils literal notranslate"><span class="pre">--version</span></code> it tells you which version of python it is “connected” to.</p>
</div>
<div class="section" id="for-git">
<h4>For git:<a class="headerlink" href="#for-git" title="Permalink to this headline">¶</a></h4>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ git --version
git version <span class="m">2</span>.15.2 <span class="o">(</span>Apple Git-101.1<span class="o">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2020, University of Washington, Natasha Aleksandrova, Christopher Barker, Brian Dorsey, Cris Ewing, Christy Heaton, Jon Jacky, Maria McKinley, Andy Miles, Rick Riehle, Joseph Schilz, Joseph Sheedy, Hosung Song. Creative Commons Attribution-ShareAlike 4.0 license
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>