-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathInstalling_Python.html
227 lines (207 loc) · 19.9 KB
/
Installing_Python.html
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
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<meta content="Topic: Installing Python with Anaconda, Difficulty: Easy, Category: Tutorial" name="description" />
<meta content="python, anaconda, instructions, environments, beginner, data science, introduction" name="keywords" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Installing Python — Python Like You Mean It</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../_static/my_theme.css" type="text/css" />
<!--[if lt IE 9]>
<script src="../_static/js/html5shiv.min.js"></script>
<![endif]-->
<script data-url_root="../" id="documentation_options" 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 async="async" src="https://www.googletagmanager.com/gtag/js?id=UA-115029372-1"></script>
<script src="../_static/gtag.js"></script>
<script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
<script>window.MathJax = {"tex": {"inlineMath": [["$", "$"], ["\\(", "\\)"]], "processEscapes": true}, "options": {"ignoreHtmlClass": "tex2jax_ignore|mathjax_ignore|document", "processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}}</script>
<script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script src="../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="An Informal Introduction to Python" href="Informal_Intro_Python.html" />
<link rel="prev" title="Introducing the Python Programming Language" href="GettingStartedWithPython.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" >
<a href="../index.html" class="icon icon-home"> Python Like You Mean It
</a>
<div class="version">
1.4
</div>
<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="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Table of Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../intro.html">Python Like You Mean It</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../module_1.html">Module 1: Getting Started with Python</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="SiteFormatting.html">A Quick Guide to Formatting</a></li>
<li class="toctree-l2"><a class="reference internal" href="GettingStartedWithPython.html">Introducing the Python Programming Language</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Installing Python</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#Installing-Anaconda">Installing Anaconda</a></li>
<li class="toctree-l3"><a class="reference internal" href="#What-did-this-just-do-to-my-computer?">What did this just do to my computer?</a></li>
<li class="toctree-l3"><a class="reference internal" href="#A-Brief-Introduction-to-Conda-Environments">A Brief Introduction to Conda Environments</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="Informal_Intro_Python.html">An Informal Introduction to Python</a></li>
<li class="toctree-l2"><a class="reference internal" href="Jupyter_Notebooks.html">Jupyter Notebooks</a></li>
<li class="toctree-l2"><a class="reference internal" href="Getting_Started_With_IDEs_and_Notebooks.html">Setting Up a Development Environment</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../module_2.html">Module 2: The Essentials of Python</a></li>
<li class="toctree-l1"><a class="reference internal" href="../module_2_problems.html">Module 2: Problems</a></li>
<li class="toctree-l1"><a class="reference internal" href="../module_3.html">Module 3: The Essentials of NumPy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../module_3_problems.html">Module 3: Problems</a></li>
<li class="toctree-l1"><a class="reference internal" href="../module_4.html">Module 4: Object Oriented Programming</a></li>
<li class="toctree-l1"><a class="reference internal" href="../module_5.html">Module 5: Odds and Ends</a></li>
<li class="toctree-l1"><a class="reference internal" href="../changes.html">Changelog</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">Python Like You Mean It</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html" class="icon icon-home"></a> »</li>
<li><a href="../module_1.html">Module 1: Getting Started with Python</a> »</li>
<li>Installing Python</li>
<li class="wy-breadcrumbs-aside">
<a href="../_sources/Module1_GettingStartedWithPython/Installing_Python.md.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">
<style>
/* CSS overrides for sphinx_rtd_theme */
/* 24px margin */
.nbinput.nblast.container,
.nboutput.nblast.container {
margin-bottom: 19px; /* padding has already 5px */
}
/* ... except between code cells! */
.nblast.container + .nbinput.container {
margin-top: -19px;
}
.admonition > p:before {
margin-right: 4px; /* make room for the exclamation icon */
}
/* Fix math alignment, see https://github.com/rtfd/sphinx_rtd_theme/pull/686 */
.math {
text-align: unset;
}
</style>
<section id="Installing-Python">
<h1>Installing Python<a class="headerlink" href="#Installing-Python" title="Permalink to this headline"></a></h1>
<p>Without further ado, we now provide instructions for installing Python and other useful Python libraries on your machine via the Anaconda platform. Installing the Anaconda platform will install the following:</p>
<ul class="simple">
<li><p>Python; specifically the CPython interpreter that we discussed in the previous section.</p></li>
<li><p>A number of useful Python packages, like matplotlib, NumPy, and SciPy.</p></li>
<li><p>Jupyter, which provides an interactive “notebook” environment for prototyping code.</p></li>
<li><p>conda: a package manager that will allow you to install and update Python and additional Python packages, while handling all compatibility issues for you.</p></li>
</ul>
<p>Note that installing Python via Anaconda will <strong>not</strong> break any other installations of Python that already exist on your computer. See <a class="reference external" href="#What-did-this-just-do-to-my-computer?">What did this just do to my computer?</a> for more details.</p>
<p>Some of the packages provided by Anaconda, like NumPy, have been <a class="reference external" href="https://docs.anaconda.com/mkl-optimizations/">optimized</a> and will run significantly faster than if you installed them manually.</p>
<div class="admonition note">
<p class="admonition-title fa fa-exclamation-circle"><strong>Takeaway</strong>:</p>
<p>“Anaconda” is a collection of the CPython interpreter and a number of very popular Python libraries for doing data science-related work. It also provides a package manager for downloading/updating Python packages, and an environment manager for maintaining independent installations of Python side-by-side.</p>
</div>
<section id="Installing-Anaconda">
<h2>Installing Anaconda<a class="headerlink" href="#Installing-Anaconda" title="Permalink to this headline"></a></h2>
<ol class="arabic simple">
<li><p>Navigate to <a class="reference external" href="https://www.anaconda.com/download/">this page</a>, and click the “Download” button for <strong>Python 3</strong>.</p></li>
<li><p>After the download is complete, begin the installation process. There will be an installation option: <code class="docutils literal notranslate"><span class="pre">Add</span> <span class="pre">Anaconda</span> <span class="pre">to</span> <span class="pre">the</span> <span class="pre">system</span> <span class="pre">PATH</span> <span class="pre">environment</span> <span class="pre">variable</span></code>; we advise you to <strong>enable</strong> this installation option (advanced users: see below for caveats).</p></li>
<li><p>Complete the 30 minute <a class="reference external" href="https://conda.io/projects/conda/en/latest/user-guide/getting-started.html">“Getting Started”</a> tutorial to familiarize yourself with <code class="docutils literal notranslate"><span class="pre">conda</span></code>. This is very important!</p></li>
</ol>
<p>You will need to know how to open a terminal (cmd.exe for Windows users) on your computer, and how to navigate between directories in the terminal. If you do not know how to do this, read a ‘how-to’ for whatever operating system you are using.</p>
</section>
<section id="What-did-this-just-do-to-my-computer?">
<h2>What did this just do to my computer?<a class="headerlink" href="#What-did-this-just-do-to-my-computer?" title="Permalink to this headline"></a></h2>
<p>This created a directory called <code class="docutils literal notranslate"><span class="pre">Anaconda3</span></code> (or some variant of this) on your computer, which contains all of the files associated with the CPython interpreter, all of the modules in Python’s standard library, the aforementioned 3rd party packages that come as part of the Anaconda distribution (e.g. NumPy, SciPy, Jupyter, iPython), and the <code class="docutils literal notranslate"><span class="pre">conda</span></code> package manager. It also contains the executable files for all of these applications. The default install location for Anaconda is:</p>
<ul class="simple">
<li><p>(Linux): <code class="docutils literal notranslate"><span class="pre">/home/<your_username>/Anaconda3</span></code></p></li>
<li><p>(Windows): <code class="docutils literal notranslate"><span class="pre">C:\Users\<your_username>\Anaconda3</span></code></p></li>
<li><p>(Mac): <code class="docutils literal notranslate"><span class="pre">/Users/<your_username>/Anaconda3</span></code></p></li>
</ul>
<p>If you followed the install instructions as specified above, then the Anaconda-installer also <em>placed this directory in your system’s “path”</em>. Let’s briefly discuss what this means. Your system’s path is simply a list of directories. Whenever you execute any command in your computer’s terminal, the computer will quickly search through the directories that are specified in the path for an executable with that name; <em>it will execute the first such executable that it finds</em>. Thus, by placing the
<code class="docutils literal notranslate"><span class="pre">Anaconda3</span></code> directory at the beginning of your path, the Anaconda-installer has ensured that your computer will prioritize Anaconda’s python executable over any other installations of Python on your computer, because it will find that executable first.</p>
<p>For Linux and Mac users, it is very likely that your system already has a version of Python installed. <em>It is critical that you do not attempt to uninstall, remove, or change this native version of Python</em>. Those operating systems use their native versions of Python to perform some of their services. Those services are written such that they will directly invoke the Python executable that came with the operating system - they will not accidentally run the version of Python that came with
Anaconda. At the end of the day you can simply install Anaconda without worrying about any of these details.</p>
<p><strong>An important note for people who code in languages other than Python:</strong> Anaconda has its own <code class="docutils literal notranslate"><span class="pre">lib</span></code> and <code class="docutils literal notranslate"><span class="pre">bin</span></code> directories that it uses to store library files and binary files as needed. While this makes it very easy for users to install sophisticated Python packages that leverage C-libraries without having to manually build those libraries, it also means that your system will prioritize Anaconda’s files before your system-level files. This can be a big problem if you work in languages other
than Python.</p>
<p>The simple solution to this is to <em>not</em> have the Anaconda-installer include Anaconda in your path. Instead, you can create an alias that will allow you manually prepend Anaconda to your path. E.g., in Linux you can add the following alias to your <code class="docutils literal notranslate"><span class="pre">~/.bashrc</span></code> file:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="nb">alias</span> <span class="nv">anaconda</span><span class="o">=</span><span class="s2">"export PATH=/home/<your_username>/anaconda3/bin:</span><span class="nv">$PATH</span><span class="s2">"</span>
</pre></div>
</div>
<p>With this alias in place, you can simply invoke the command <code class="docutils literal notranslate"><span class="pre">anaconda</span></code> in your terminal to place Anaconda at the beginning of your path for that terminal session.</p>
</section>
<section id="A-Brief-Introduction-to-Conda-Environments">
<h2>A Brief Introduction to Conda Environments<a class="headerlink" href="#A-Brief-Introduction-to-Conda-Environments" title="Permalink to this headline"></a></h2>
<p><code class="docutils literal notranslate"><span class="pre">conda</span></code> is not only a package manager, but also a powerful environment manager. Let’s take a moment to motivate a common use case for environment management before we dive into what it actually is:</p>
<blockquote>
<div><p>It is expected and encouraged that you work through Python Like You Mean It using the latest version of Python (Python 3.X). That being said, it is not uncommon to encounter courses and projects that require you to use Python 2.7, which is a dead version of the language. Is there a simple and sane way to switch back and forth between working in Python 3 and Python 2.7 environments? Yes! Utilizing conda environments is a perfect way to solve this problem.</p>
</div></blockquote>
<p>Assuming that your initial installation of Anaconda contained Python 3, then your <em>root</em> (i.e. default) conda environment is that Python 3 environment. You can now create a conda environment that instead includes Python 2.7 and all of the 3rd party packages that come with Anaconda. Execute the following command in your terminal:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>conda create -n py27 <span class="nv">python</span><span class="o">=</span><span class="m">2</span>.7 anaconda
</pre></div>
</div>
<p>Once the installation process is complete, you will be able to activate this environment, which we have named <code class="docutils literal notranslate"><span class="pre">py27</span></code>, by executing the command:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>conda activate py27
</pre></div>
</div>
<p>Activating an environment simply updates your system’s path, swapping the directory <code class="docutils literal notranslate"><span class="pre">Anaconda3</span></code> with <code class="docutils literal notranslate"><span class="pre">Anaconda3/envs/py27</span></code> in this instance. Thus your system will now find the Python 2.7 executable and its associated libraries in its path. Note that this path change only occurs effect in <em>that particular terminal session</em>. Any other terminal session will default to the root conda environment.</p>
<p>Having activated your <code class="docutils literal notranslate"><span class="pre">py27</span></code> environment, you can start a vanilla Python console, an iPython console, a Jupyter notebook, run a Python script, etc. These will now all use Python 2.7. You can also use <code class="docutils literal notranslate"><span class="pre">conda</span></code> (and <code class="docutils literal notranslate"><span class="pre">pip</span></code>) to install Python 2.7-compatible packages in this environment. As long as your path points to <code class="docutils literal notranslate"><span class="pre">Anaconda3/envs/py27</span></code> and not <code class="docutils literal notranslate"><span class="pre">Anaconda3</span></code>, it is as if this is the only version of Python that lives on your computer.</p>
<p>Deactivating this environment will return you to the root Python 3 environment. That is, it will switch your path back to including <code class="docutils literal notranslate"><span class="pre">Anaconda3</span></code> instead of <code class="docutils literal notranslate"><span class="pre">Anaconda3/envs/py27</span></code>. Simply invoke the command:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>conda deactivate
</pre></div>
</div>
<p>And like that, conda environments give you all of the powers of a necromancer, allowing you to nimbly cross back and forth between the land of the living (Python 3) and the dead (Python 2.7).</p>
<p>Conda environments have more uses than simply switching back and forth between Python 3 and 2. Many people like to make a new conda environment for every major project that they work on, so that they can freely install any dependencies that are needed for that particular project, without worrying about conflicts with their other work. You should be keen on making regular use of conda environments.</p>
<p>It is highly recommended that you take time to read through <a class="reference external" href="https://conda.io/docs/user-guide/tasks/manage-environments.html">this tutorial on managing conda environments</a>.</p>
</section>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="GettingStartedWithPython.html" class="btn btn-neutral float-left" title="Introducing the Python Programming Language" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="Informal_Intro_Python.html" class="btn btn-neutral float-right" title="An Informal Introduction to Python" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>© Copyright 2021, Ryan Soklaski.</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>