Repository navigation
Expand file tree
/
Copy pathpython_for_linux.html
More file actions
424 lines (311 loc) · 21.3 KB
/
Copy pathpython_for_linux.html
File metadata and controls
424 lines (311 loc) · 21.3 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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
<!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 Linux 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 Linux for Python</li>
<li class="wy-breadcrumbs-aside">
<a href="../../_sources/modules/dev_environment/python_for_linux.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-linux-for-python">
<span id="python-for-linux"></span><h1>Setting Up Linux for Python<a class="headerlink" href="#setting-up-linux-for-python" title="Permalink to this headline">¶</a></h1>
<div class="section" id="debian-and-related-distros-ubuntu-linux-mint">
<h2>Debian and Related Distros (Ubuntu, Linux Mint)<a class="headerlink" href="#debian-and-related-distros-ubuntu-linux-mint" title="Permalink to this headline">¶</a></h2>
<div class="section" id="python">
<h3>Python<a class="headerlink" href="#python" title="Permalink to this headline">¶</a></h3>
<p>For this program, you need Python3.6.* or 3.7.*</p>
<p>Debian distros already have the stable python2 and python3 releases preinstalled (<a class="reference external" href="https://wiki.debian.org/Python">Debian Wiki</a>).</p>
<p>Try the following command:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ python3
Python <span class="m">3</span>.6.3 <span class="o">(</span>default, March <span class="m">26</span> <span class="m">2017</span>, <span class="m">15</span>:33:32<span class="o">)</span>
<span class="o">[</span>GCC <span class="m">4</span>.9.2 on linux<span class="o">]</span>
>>>
</pre></div>
</div>
<p>I’m pretty sure that 18.4 (the most recent long term support release) has 3.6, if so, you are set.</p>
<p>That’s nice, which one is the default version? Just type <code class="docutils literal notranslate"><span class="pre">python</span></code> to see. It’s probably python2 still:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ python
Python <span class="m">2</span>.7.9 <span class="o">(</span>default, April <span class="m">2</span> <span class="m">2015</span>, <span class="m">15</span>:33:32<span class="o">)</span>
<span class="o">[</span>GCC <span class="m">4</span>.9.2 on linux2<span class="o">]</span>
>>>
</pre></div>
</div>
<p>If you want to make <code class="docutils literal notranslate"><span class="pre">python3.6</span></code> the default version then add the line <code class="docutils literal notranslate"><span class="pre">alias</span> <span class="pre">python=python3</span></code> to your user’s <code class="docutils literal notranslate"><span class="pre">/home/{user}/.bashrc</span></code> file like so:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ <span class="c1"># before the change</span>
$ python
Python <span class="m">2</span>.7.9 <span class="o">(</span>default, April <span class="m">2</span> <span class="m">2015</span>, <span class="m">15</span>:33:32<span class="o">)</span>
<span class="o">[</span>GCC <span class="m">4</span>.9.2 on linux2<span class="o">]</span>
>>>
$ <span class="nb">echo</span> <span class="s2">"alias python=python3"</span> >> ~/.bashrc
$ <span class="nb">echo</span> <span class="s2">"alias pip=pip3"</span> >> ~/.bashrc
$ <span class="nb">echo</span> <span class="s2">"alias ipython=ipython3"</span> >> ~/.bashrc
$ <span class="nb">source</span> ~/.bashrc
$ <span class="c1"># after the change</span>
$ python
Python <span class="m">3</span>.6.3 <span class="o">(</span>default, March <span class="m">26</span> <span class="m">2017</span>, <span class="m">15</span>:33:32<span class="o">)</span>
<span class="o">[</span>GCC <span class="m">4</span>.9.2 on linux<span class="o">]</span>
>>>
</pre></div>
</div>
<p>Alternatively, you can always remember to type <code class="docutils literal notranslate"><span class="pre">python3</span></code> whenever you want Python.</p>
<p>Note: your version number may vary, but it needs to be <code class="docutils literal notranslate"><span class="pre">3.6.*</span></code> or <code class="docutils literal notranslate"><span class="pre">3.7.*</span></code></p>
<p>You may not have pip and ipython installed yet, but you will as you follow the instructions below.</p>
<p>If you don’t have the version you want installed then use the package manager to find and install it:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ <span class="c1"># search the package manager for it</span>
$ sudo apt-cache search python <span class="p">|</span> grep <span class="s1">'^python3.7\ -'</span>
python3.7 - Interactive high-level object-oriented language <span class="o">(</span>version <span class="m">3</span>.7<span class="o">)</span>
$ <span class="c1"># install it</span>
$ sudo apt-get install python3.7
</pre></div>
</div>
<p>(If you cant find 3.7, try 3.6 instead)</p>
</div>
<div class="section" id="terminal">
<h3>Terminal<a class="headerlink" href="#terminal" title="Permalink to this headline">¶</a></h3>
<p>Every Linux box has a terminal emulator – find and use it.</p>
</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.</p>
<p>Many Python packages are also available directly from your distro – but you’ll get the latest and greatest if you use <code class="docutils literal notranslate"><span class="pre">pip</span></code> to install it instead.</p>
<p>To get pip, the first option is to use your system package manager, something like:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ sudo apt-get install python3-pip
</pre></div>
</div>
<p>If that doesn’t work, then try “ensure-pip”:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span> $ python3 -m ensurepip --upgrade
$ python3 -m ensurepip --upgrade
</pre></div>
</div>
<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 (could be <code class="docutils literal notranslate"><span class="pre">python3</span></code>)</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>Which often works, but also can invoke the <em>wrong</em> version of pip. The above 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 (in this case python3).</p>
</div>
<div class="section" id="ipython">
<h3>iPython<a class="headerlink" href="#ipython" title="Permalink to this headline">¶</a></h3>
<p>One extra package we are going to use in class is <code class="docutils literal notranslate"><span class="pre">iPython</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ sudo python3 -m pip install ipython
</pre></div>
</div>
<p>You should now be able to run <code class="docutils literal notranslate"><span class="pre">iPython</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ipython3
Python 3.6.4 ()
Type "copyright", "credits" or "license" for more information.
IPython 2.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
</pre></div>
</div>
</div>
<div class="section" id="git">
<h3>git<a class="headerlink" href="#git" title="Permalink to this headline">¶</a></h3>
<p>Git is likely to be there on your system already, but if not:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ sudo apt-get install git
</pre></div>
</div>
<div class="section" id="fedora-and-red-hat-related-distros-centos">
<h4>Fedora and Red Hat Related Distros (CentOS)<a class="headerlink" href="#fedora-and-red-hat-related-distros-centos" title="Permalink to this headline">¶</a></h4>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>CentOS is probably the most popular distro of these related flavors. However, getting Python3 on it can be a pain. You have been warned! (but there are lots of tutorials on the web – google “install python3 on CentOS”)</p>
</div>
</div>
</div>
<div class="section" id="id1">
<h3>Python<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<p>Fedora distros already have the stable python2 and python3 releases preinstalled <a class="reference external" href="FedoraWiki">[2]</a>. However, CentOS, the most popular distro only has the stable python2 release. Try the following commands:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">[</span>centos@ip-172-31-21-5 ~<span class="o">]</span>$ python2
Python <span class="m">2</span>.7.5 <span class="o">(</span>default, Jun <span class="m">17</span> <span class="m">2014</span>, <span class="m">18</span>:11:42<span class="o">)</span>
<span class="o">[</span>GCC <span class="m">4</span>.8.2 <span class="m">20140120</span> <span class="o">(</span>Red Hat <span class="m">4</span>.8.2-16<span class="o">)]</span> on linux2
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.
>>>
<span class="o">[</span>centos@ip-172-31-21-5 ~<span class="o">]</span>$ python3
-bash: python3: <span class="nb">command</span> not found
</pre></div>
</div>
<p>Let’s install python3 using the package manager. Step one install “Software Collections” to help us:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ sudo yum -y install scl-utils
</pre></div>
</div>
<p>Then go to the <a class="reference external" href="https://www.softwarecollections.org/en/scls/">software collections listing</a> and click on the Python collection version you want to install.</p>
<p>Probably this one:</p>
<p><a class="reference external" href="https://www.softwarecollections.org/en/scls/rhscl/rh-python35/">https://www.softwarecollections.org/en/scls/rhscl/rh-python35/</a></p>
<p>Note, you also need to know which version of CentOS you are using (probably 6 or 7). For example, we care about <cite>python version 3.5</cite> so let’s go the <cite>.rpm</cite> i want to install <a class="reference external" href="https://www.softwarecollections.org/repos/rhscl/rh-python35/epel-7-x86_64/noarch/">here</a>:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ <span class="c1"># add this package to the rpm package manager</span>
$ sudo rpm -Uvh https://www.softwarecollections.org/repos/rhscl/rh-python34/epel-7-x86_64/noarch/rhscl-rh-python35-epel-7-x86_64.noarch.rpm
$ <span class="c1"># install the right python version</span>
$ sudo yum install rh-python35
</pre></div>
</div>
<p>When you want to use python3 run this command:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">[</span>centos@ip-172-31-21-5 ~<span class="o">]</span>$ scl <span class="nb">enable</span> rh-python35 bash
</pre></div>
</div>
</div>
<div class="section" id="id3">
<h3>Terminal<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h3>
<p>Every Linux box has a terminal emulator – find and use it.</p>
</div>
<div class="section" id="id4">
<h3>git<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h3>
<p>Git is likely to be there on your system already, but if not:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ sudo yum install git
</pre></div>
</div>
</div>
<div class="section" id="id5">
<h3>pip<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h3>
<p><code class="docutils literal notranslate"><span class="pre">pip</span></code> is the Python package installer.</p>
<p>Many Python packages are also available directly from your distro – but you’ll get the latest and greatest if you use <code class="docutils literal notranslate"><span class="pre">pip</span></code> to install it instead.</p>
<p>In CentOS, if you used the above technique to install Python3, then it comes with pip. Try:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">[</span>centos@ip-172-31-21-5 ~<span class="o">]</span>$ python -m pip -V
pip <span class="m">8</span>.1.2 from /opt/rh/rh-python35/root/usr/lib/python3.5/site-packages <span class="o">(</span>python <span class="m">3</span>.5<span class="o">)</span>
</pre></div>
</div>
</div>
<div class="section" id="id6">
<h3>Using pip:<a class="headerlink" href="#id6" 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">python</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">python</span></code> is the command you use to invoke the Python you want to use (could be <cite>python3</cite>)</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>Which often works, but also can invoke the <em>wrong</em> version of pip. The above command:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ python -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="id7">
<h3>iPython<a class="headerlink" href="#id7" title="Permalink to this headline">¶</a></h3>
<p>One we are going to use in class is <code class="docutils literal notranslate"><span class="pre">iPython</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ sudo pip install ipython[all]
</pre></div>
</div>
<p>You should now be able to run <code class="docutils literal notranslate"><span class="pre">iPython</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ipython3
Python 3.5.2 ()
Type "copyright", "credits" or "license" for more information.
IPython 5.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
</pre></div>
</div>
</div>
</div>
<div class="section" id="footnotes">
<h2>Footnotes:<a class="headerlink" href="#footnotes" title="Permalink to this headline">¶</a></h2>
</div>
<div class="section" id="id8">
<h2>Debian Wiki<a class="headerlink" href="#id8" title="Permalink to this headline">¶</a></h2>
<p><a class="reference external" href="https://wiki.debian.org/Python">https://wiki.debian.org/Python</a></p>
</div>
<div class="section" id="fedora-wiki">
<h2>Fedora Wiki<a class="headerlink" href="#fedora-wiki" title="Permalink to this headline">¶</a></h2>
<p><a class="reference external" href="https://fedoraproject.org/wiki/Packaging:Python">https://fedoraproject.org/wiki/Packaging:Python</a></p>
</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>