-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththe-ultimate-guide-to-setup-multiple-python-environment-with-anaconda-and-sublime-text.html
executable file
·272 lines (247 loc) · 14 KB
/
the-ultimate-guide-to-setup-multiple-python-environment-with-anaconda-and-sublime-text.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>The ultimate guide to setup multiple Python environment with Anaconda and Sublime Text</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="Carson's Tech Hut Full Atom Feed" />
<link href="/feeds/python-environment.atom.xml" type="application/atom+xml" rel="alternate" title="Carson's Tech Hut Categories Atom Feed" />
<script>
/* Javascript code to toggle between adding and removing the
"responsive" class to nav when the user clicks on the icon */
function myFunction() {
var x = document.getElementById("nav-bar");
if (x.className === "nav") {
x.className += " responsive";
} else {
x.className = "nav";
}
}
</script>
</head>
<body>
<div class="navigation pure-menu pure-menu-horizontal">
<div class="nav", id="nav-bar">
<a href="/" class="page-container pure-menu-heading pure-menu-link nav">Carson's Tech Hut</a>
<ul class="pure-menu-list">
<li class="pure-menu-item"><a href="../archives.html" class="pure-menu-link">All posts</a></li>
<li class="pure-menu-item"><a href="../categories.html" class="pure-menu-link">Categories</a></li>
<li class="pure-menu-item"><a href="../tags.html" class="pure-menu-link">Tags</a></li>
</ul>
<a href="javascript:void(0);" class="icon pure-menu-link" onclick="myFunction()">
<i class="fas fa-bars"></i>
</a>
</div>
</div>
<div class="page-container">
<div class="entry-content">
<div class="post-meta pure-u">
<div class="pure-u">
<img src="../theme/images/authors/Logo.png" class="post-avatar" alt="Go to the profile of Carson Zhang">
</div>
<div class="pure-u meta-data">
<a href="/author/carson-zhang.html" class="category">Carson Zhang</a><br />
Senior Software Developer
<br />
<abbr title="2018-02-11T00:00:00-07:00">Sun 11 February 2018</abbr>
• 10 min read
</div>
</div>
</div>
<div class="article-header-container">
<div class="background-image-container">
<div class="background-image-small">
<div class="title-container">
<h1>The ultimate guide to setup multiple Python environment with Anaconda and Sublime Text</h1>
</div>
</div>
</div>
</div>
<div class="entry-content">
<!--
<div align="right">
Author:<br>
<a href="/author/carson-zhang.html">Carson Zhang</a><br>
</div>
-->
<p>The need for setting up a virtual executing environment of Python has a lot of advantages and has been widely discussed over internet. Here I have a tutorial for setting up multiple environment with Anaconda and Sublime Text. </p>
<ul>
<li>The reason I choose Anaconda over Virtualenv is because Anaconda is widely used in the industry, especially in the big data and machine learning field, and it covers most functions of Virtualenv. </li>
<li>I choose Sublime Text as my IDE because it is very simple yet powerful with many plugins. It is way faster and more efficient than many other IDES. </li>
<li>The installation of Anaconda will not be covered here as there are many tutorials online already. </li>
</ul>
<p>The tutorial has the following steps:</p>
<ul>
<li><a href="#step-1-install-anaconda-3"><a name="step1"></a>Step 1: install Anaconda 3</a></li>
<li><a href="#step-2-setup-python-environment-with-anaconda-on-win-10"><a name="step2"></a>Step 2: setup python environment with Anaconda on Win 10</a></li>
<li><a href="#step-3-setup-sublime-text-build-file-on-win-10"><a name="step3"></a>Step 3: setup Sublime Text build file on Win 10</a></li>
<li><a href="#step-4-setup-python-environment-with-anaconda-on-mac"><a name="step4"></a>Step 4: setup python environment with Anaconda on Mac</a></li>
<li><a href="#step-5-setup-sublime-text-build-file-on-mac"><a name="step5"></a>Step 5: setup Sublime Text build file on Mac</a></li>
<li><a href="#summary-of-useful-conda-commands"><a name="summary"></a>Summary of useful conda commands</a></li>
</ul>
<h2><a name="step1"></a>Step 1: install Anaconda 3</h2>
<ol>
<li>Install <a href="https://www.anaconda.com/download/"><strong>Anaconda 3</strong></a>. Choose the version that you use most frequently. <ul>
<li>For example, if you are working with python 3.6 most of the time, you should download the 3.6 version; otherwise, you can download the 2.7 version.</li>
</ul>
</li>
<li>If you encounter any difficulties during installation, <a href="www.google.com">google</a> and <a href="https://stackoverflow.com/">stackoverflow</a> are your best friend:)</li>
</ol>
<h2><a name="step2"></a>Step 2: setup python environment with Anaconda on Win 10</h2>
<ol>
<li>Open <strong>Anaconda Prompt</strong> to create new environment. Note that it is the Anaconda Prompt not the windows command line. <br>
<img height="500" src="https://github.com/zmcddn/Blog_Images/raw/master/tutorials/20180211/20180211_1.png"/></li>
<li>When the Anaconda Prompt opens, it is in the default directory with many packages pre-installed. Now you can install the missing packages that you need using <code>conda install <package_name></code><ul>
<li>For instance, you can install multiple packages at the same time using <code>conda install Django flask tornado twisted</code></li>
</ul>
</li>
<li>If there are some packages that cannot be installed using <code>conda</code> command, you can use <code>pip</code> as described in the following steps.</li>
<li>Once the packages are installed, you can create your own brand-new python 3.6 environment using <code>conda create -n py36 –clone base</code> as the following picture indicates.<ul>
<li>Since it is a clone from the base, all the packages you installed can be used here. This will save a lot of time. <br>
<img width="500" src="https://github.com/zmcddn/Blog_Images/raw/master/tutorials/20180211/20180211_2.png"/></li>
<li><strong>NOTE</strong> that you can also create the environment using <code>conda create -n <environment_name></code> first and then install all the necessary packages</li>
</ul>
</li>
<li>Use <code>activate py36</code> to get into the environment you just created, and use pip to install the packages that cannot be installed with "conda". <ul>
<li>For example, wxpython can be install using pip command as follows (i.e. <code>pip install -U wxpython</code>):
<img width="500" src="https://github.com/zmcddn/Blog_Images/raw/master/tutorials/20180211/20180211_3.png"/></li>
</ul>
</li>
<li>You can use <code>python</code> command to check the version of python and <code>quit()</code> command to quit the python environment as follows: <br>
<img width="600" src="https://github.com/zmcddn/Blog_Images/raw/master/tutorials/20180211/20180211_4.png"/></li>
<li>Use <code>deactivate</code> to quit current environment</li>
<li>Now the python 3.6 environment is fully prepared, we can add the python 2.7 environment using <code>conda create -n py27 python=2.7</code></li>
<li>Once the 2.7 environment is created, again you can use <code>activate py27</code> to get into the environment and use <code>conda install <package_name></code> or <code>pip</code> to install packages as instructed above.</li>
<li>When inside your base/root directory, you can use <code>conda info --envs</code> to check the current environments installed on your computer as follows:<br>
<img alt="Alt text" src="https://github.com/zmcddn/Blog_Images/raw/master/tutorials/20180211/20180211_5.png"> </li>
</ol>
<h2><a name="step3"></a>Step 3: setup Sublime Text build file on Win 10</h2>
<ol>
<li>Navigate to the <strong>New Build System</strong> <br>
<img width="500" src="https://github.com/zmcddn/Blog_Images/raw/master/tutorials/20180211/20180211_6.png"/></li>
<li>Type the following JSON format code as follows. The path on the 4th line is the path to the python environment we created above. <br>
<img alt="Alt text" src="https://github.com/zmcddn/Blog_Images/raw/master/tutorials/20180211/20180211_7.png">
<!-- <img width="600" src="https://github.com/zmcddn/Blog_Images/raw/master/tutorials/20180211/20180211_7.png"/> --></li>
<li>Save the file with an extension <code>.sublime-build</code> into the default folder </li>
<li>Repeat steps 1 to 3 to setup for the other python environment.</li>
<li>Now you can see the files you just saved have appeared in the "Build System". <ul>
<li>For example, I named as <code>py27</code> and <code>py36</code> and they have appeared as shown in step 1</li>
</ul>
</li>
<li>Now you can check the versions of python by run different build using the following codes.<br>
Run with Py36:<br>
<img width="500" src="https://github.com/zmcddn/Blog_Images/raw/master/tutorials/20180211/20180211_8.png"/><br>
Run with Py27:<br>
<img width="500" src="https://github.com/zmcddn/Blog_Images/raw/master/tutorials/20180211/20180211_9.png"/></li>
<li><strong>NOTE:</strong> the anaconda path for Win 10 is usually <code>D:/Anaconda3/envs/<environemnt_name>/python</code></li>
</ol>
<h2><a name="step4"></a>Step 4: setup python environment with Anaconda on Mac</h2>
<ol>
<li>Setting up python with Anaconda on Mac is pretty much the same as on Win 10, except that when you activate the environment, you have to use command "source activate" rather than "activate". <br>
<img alt="Alt text" src="https://github.com/zmcddn/Blog_Images/raw/master/tutorials/20180211/20180211_11.png"></li>
<li>For package installation, it is identical to the steps for Win 10 described above. You can simply follow the steps in <a href="#step2">Step 2</a></li>
</ol>
<h2><a name="step5"></a>Step 5: setup Sublime Text build file on Mac</h2>
<ol>
<li>Navigate to the "New Build System" <br>
<img alt="Alt text" src="https://github.com/zmcddn/Blog_Images/raw/master/tutorials/20180211/20180211_10.png"></li>
<li>Find the Anaconda path of python environment. The following steps explains how to do it:<ol>
<li>Open a terminal, and activate the environment you would like to set up.<ul>
<li>For example, <code>source activate py27</code></li>
</ul>
</li>
<li>Use command <code>which python</code> to find out the path</li>
<li>Don't close the terminal and remember the path. The above two steps canbe seen as follows: <br>
<img alt="Alt text" src="https://github.com/zmcddn/Blog_Images/raw/master/tutorials/20180211/20180211_12.png"></li>
</ol>
</li>
<li>Use the path find above and type the following code as follows: <br>
<img width="500" src="https://github.com/zmcddn/Blog_Images/raw/master/tutorials/20180211/20180211_13.PNG"/></li>
<li>Save it to the default location with the <code>.sublime-build</code> extension. </li>
<li>You can repeat steps 1 to 4 for other environment you have created.</li>
<li>To double check, run the following command and see the results: <br>
<img alt="Alt text" src="https://github.com/zmcddn/Blog_Images/raw/master/tutorials/20180211/20180211_14.png"></li>
<li><strong>NOTE:</strong> the anaconda path for Mac is usually <code>/Users/<user_name>/anaconda3/envs/<environemnt_name>/bin/python</code></li>
</ol>
<h2><a name="summary"></a>Summary of useful conda commands</h2>
<hr>
<table>
<thead>
<tr>
<th>Commands</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>conda list</td>
<td>list all the packages installed</td>
</tr>
<tr>
<td>conda info --envs</td>
<td>list all the environment created</td>
</tr>
<tr>
<td>conda create -n *environment_name</td>
<td>create an environment</td>
</tr>
<tr>
<td>conda create --name *name1 --clone *name2</td>
<td>create a new environment (name1) to be a clone of another (name2) one</td>
</tr>
<tr>
<td>conda install *package1 *package2</td>
<td>install multipe packages at the same time</td>
</tr>
<tr>
<td>conda install *package = version</td>
<td>install a package with a particular version</td>
</tr>
</tbody>
</table>
<ul>
<li>For more environment management commands, you can find them <a href="https://conda.io/docs/user-guide/tasks/manage-environments.html"><strong>HERE</strong></a></li>
</ul>
</div>
<footer>
<div class="tags">
<a href="/tag/python.html">Python</a>
<a href="/tag/anaconda.html">Anaconda</a>
<a href="/tag/sublime-text.html">Sublime Text</a>
<a href="/tag/environment-setup.html">Environment Setup</a>
</div>
<div class="pure-g post-footer">
<div class="pure-g">
<div class="pure-g poster-info">
<div class="pure-u">
<a href="/author/carson-zhang.html"><img src="../theme/images/authors/Logo.png" alt=""></a>
</div>
<div class="pure-u">
<h3 class="author-name"><a href="/author/carson-zhang.html">Carson Zhang</a></h3>
<p class="author-description">
I'm a senior software developer, passionated with artificial intellgence and
web development.
</p>
</div>
</div>
</div>
<!--
-->
</div>
</footer>
</div>
<footer class="index-footer">
<div class="footer-wide">
<p><a href="">Carson's Tech Hut</a>© Carson Zhang 2020</p>
</div>
<div class="footer-narrow">
<p><a href="">Carson's Tech Hut</a><br>
© Carson Zhang 2020</p>
</div>
</footer>
<link rel="stylesheet" href="../theme/css/pure-min.css" />
<link rel="stylesheet" href="../theme/css/grids-responsive-min.css" />
<link rel="stylesheet" href="../theme/fontawesome-free-5.13.0-web/css/all.min.css" />
<link rel="stylesheet" href="/theme/css/main.css" />
</body>
</html>