Repository navigation
Expand file tree
/
Copy pathvirtualenv.html
More file actions
533 lines (427 loc) · 27.8 KB
/
Copy pathvirtualenv.html
File metadata and controls
533 lines (427 loc) · 27.8 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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
<!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>Working with Virtualenv — 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>Working with Virtualenv</li>
<li class="wy-breadcrumbs-aside">
<a href="../../_sources/modules/dev_environment/virtualenv.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="working-with-virtualenv">
<span id="virtualenv-section"></span><h1>Working with Virtualenv<a class="headerlink" href="#working-with-virtualenv" title="Permalink to this headline">¶</a></h1>
<p>“For every non-standard package installed in a system Python, the gods kill a kitten”</p>
<blockquote>
<div><ul class="simple">
<li><p>me</p></li>
</ul>
</div></blockquote>
<div class="section" id="reasons-why">
<h2>Reasons Why<a class="headerlink" href="#reasons-why" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><p>As a working developer you will need to install packages that aren’t in the
Python standard Library</p></li>
<li><p>As a working developer you often need to install <em>different</em> versions of the
<em>same</em> library for different projects</p></li>
<li><p>Conflicts arising from having the wrong version of a dependency installed can
cause long-term nightmares</p></li>
<li><p>Use <a class="reference external" href="http://www.virtualenv.org/">virtualenv</a> …</p></li>
<li><p><strong>Always</strong></p></li>
</ul>
<div class="section" id="installing-virtualenv">
<h3>Installing Virtualenv<a class="headerlink" href="#installing-virtualenv" title="Permalink to this headline">¶</a></h3>
<p>The best way is to install directly in your system Python (one exception to the rule).</p>
<p>To do so you will have to have <a class="reference external" href="http://www.pip-installer.org">pip</a> installed.</p>
<p>Try the following command:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ which pip
/usr/local/bin/pip
</pre></div>
</div>
<p>If the <code class="docutils literal notranslate"><span class="pre">which</span></code> command returns no value for you, then <code class="docutils literal notranslate"><span class="pre">pip</span></code> is not
installed in your system. To fix this, follow <a class="reference external" href="http://www.pip-installer.org/en/latest/installing.html">the instructions here</a>.</p>
<p>Once you have <code class="docutils literal notranslate"><span class="pre">pip</span></code> installed in your system, you can use it to install
<a class="reference external" href="http://www.virtualenv.org/">virtualenv</a>. Because you are installing it into your system Python, you will
most likely need <code class="docutils literal notranslate"><span class="pre">superuser</span></code> privileges to do so:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ sudo pip install virtualenv
Downloading/unpacking virtualenv
Downloading virtualenv-1.11.2-py2.py3-none-any.whl <span class="o">(</span><span class="m">2</span>.8MB<span class="o">)</span>: <span class="m">2</span>.8MB downloaded
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...
</pre></div>
</div>
<p>Great. Once that’s done, you should find that you have a <code class="docutils literal notranslate"><span class="pre">virtualenv</span></code>
command available to you from your shell:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ virtualenv --help
Usage: virtualenv [OPTIONS] DEST_DIR
Options:
--version show program's version number and exit
-h, --help ...
</pre></div>
</div>
</div>
</div>
<div class="section" id="using-virtualenv">
<h2>Using Virtualenv<a class="headerlink" href="#using-virtualenv" title="Permalink to this headline">¶</a></h2>
<p>Creating a new virtualenv is very very simple:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ virtualenv <span class="o">[</span>options<span class="o">]</span> <ENV>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre"><ENV></span></code> is just the name of the environment you want to create. It’s
arbitrary. Let’s make one for demonstration purposes:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ virtualenv demoenv
New python executable in demoenv/bin/python
Installing setuptools, pip...done.
</pre></div>
</div>
<div class="section" id="what-happened">
<h3>What Happened?<a class="headerlink" href="#what-happened" title="Permalink to this headline">¶</a></h3>
<p>When you ran that command, a few things took place:</p>
<ul class="simple">
<li><p>A new directory with your requested name was created</p></li>
<li><p>A new Python executable was created in <ENV>/bin (<ENV>/Scripts on Windows)</p></li>
<li><p>The new Python was cloned from your system Python (where virtualenv was
installed)</p></li>
<li><p>The new Python was isolated from any libraries installed in the old Python</p></li>
<li><p>Setuptools was installed so you have <code class="docutils literal notranslate"><span class="pre">easy_install</span></code> for this new Python</p></li>
<li><p>Pip was installed so you have <code class="docutils literal notranslate"><span class="pre">pip</span></code> for this new python</p></li>
</ul>
</div>
<div class="section" id="activation">
<h3>Activation<a class="headerlink" href="#activation" title="Permalink to this headline">¶</a></h3>
<p>The virtual environment you just created, <code class="docutils literal notranslate"><span class="pre">demoenv</span></code> contains an executable
Python command, but if you do a quick check to see which Python executable is
found by your terminal, you’ll see that it is not the one:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ which python
/usr/bin/python
</pre></div>
</div>
<p>You can execute the new Python by explicitly pointing to it:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ ./demoenv/bin/python -V
Python <span class="m">2</span>.7.5
</pre></div>
</div>
<p>but that’s tedious and hard to remember. Instead, <code class="docutils literal notranslate"><span class="pre">activate</span></code> your virtualenv
using the <code class="docutils literal notranslate"><span class="pre">source</span></code> command:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ <span class="nb">source</span> demoenv/bin/activate
<span class="o">(</span>demoenv<span class="o">)</span>$ which python
/Users/cewing/demoenv/bin/python
</pre></div>
</div>
<p>On Windows, the <em>activate</em> script is in the <code class="docutils literal notranslate"><span class="pre">Scripts</span></code> folder:</p>
<p><code class="docutils literal notranslate"><span class="pre">></span> <span class="pre">\path\to\env\Scripts\activate</span></code></p>
<p>There. That’s better. Now whenever you run the <code class="docutils literal notranslate"><span class="pre">python</span></code> command, the
executable that will be used will be the new one in your <code class="docutils literal notranslate"><span class="pre">demoenv</span></code>.</p>
<p>Notice also that the your shell prompt has changed. It indicates which
<code class="docutils literal notranslate"><span class="pre">virtualenv</span></code> is currently active. Little clues like that really help you to
keep things straight when you’ve got a lot of projects going on, so it’s nice
the makers of virtualenv thought of it.</p>
</div>
<div class="section" id="installing-packages">
<h3>Installing Packages<a class="headerlink" href="#installing-packages" title="Permalink to this headline">¶</a></h3>
<p>Now that your virtualenv is active, not only has your <code class="docutils literal notranslate"><span class="pre">python</span></code> executable been
hijacked, so have <code class="docutils literal notranslate"><span class="pre">pip</span></code> and <code class="docutils literal notranslate"><span class="pre">easy_install</span></code>:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">(</span>demoenv<span class="o">)</span>$ which pip
/Users/cewing/demoenv/bin/pip
<span class="o">(</span>demoenv<span class="o">)</span>$ which easy_install
/Users/cewing/demoenv/bin/easy_install
</pre></div>
</div>
<p>This means that using these tools to install packages will install them <em>into
your virtual environment only</em> and not into the system Python. Let’s see this
in action. We’ll install a package called <code class="docutils literal notranslate"><span class="pre">docutils</span></code> that provides support
for converting ReStructuredText documents into other formats like HTML, LaTeX
and more:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">(</span>demoenv<span class="o">)</span>$ pip install docutils
Downloading/unpacking docutils
Downloading docutils-0.11.tar.gz <span class="o">(</span><span class="m">1</span>.6MB<span class="o">)</span>: <span class="m">1</span>.6MB downloaded
Running setup.py <span class="o">(</span>path:/Users/cewing/demoenv/build/docutils/setup.py<span class="o">)</span> egg_info <span class="k">for</span> package docutils
...
changing mode of /Users/cewing/demoenv/bin/rst2xml.py to <span class="m">755</span>
changing mode of /Users/cewing/demoenv/bin/rstpep2html.py to <span class="m">755</span>
Successfully installed docutils
Cleaning up...
</pre></div>
</div>
<p>And now, when we fire up our Python interpreter, the docutils package is
available to us:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">(</span>demoenv<span class="o">)</span>$ python
Python <span class="m">2</span>.7.5 <span class="o">(</span>default, Aug <span class="m">25</span> <span class="m">2013</span>, <span class="m">00</span>:04:04<span class="o">)</span>
<span class="o">[</span>GCC <span class="m">4</span>.2.1 Compatible Apple LLVM <span class="m">5</span>.0 <span class="o">(</span>clang-500.0.68<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.
>>> import docutils
>>> docutils.__path__
<span class="o">[</span><span class="s1">'/Users/cewing/demoenv/lib/python2.7/site-packages/docutils'</span><span class="o">]</span>
>>> ^d
<span class="o">(</span>demoenv<span class="o">)</span>$
</pre></div>
</div>
<p>There’s one other interesting side-effect of installing software with
<code class="docutils literal notranslate"><span class="pre">virtualenv</span></code>. The <code class="docutils literal notranslate"><span class="pre">docutils</span></code> package provides a number of executable
scripts when it is installed: <code class="docutils literal notranslate"><span class="pre">rst2html.py</span></code>, <code class="docutils literal notranslate"><span class="pre">rst2latex.py</span></code> and so on.
These scripts are set up to execute using the Python with which they were
built. What this means is that running these scripts will use the Python
executable in your virtualenv, <em>even if that virtualenv is not active</em>!</p>
</div>
<div class="section" id="deactivation">
<h3>Deactivation<a class="headerlink" href="#deactivation" title="Permalink to this headline">¶</a></h3>
<p>So you’ve got a virtual environment created. And you’ve activated it so that
you can install packages and use them. Eventually you’ll need to move on to
some other project. This likely means that you’ll need to stop working with
this <code class="docutils literal notranslate"><span class="pre">virtualenv</span></code> and switch to another (it’s a good idea to keep a separate
<code class="docutils literal notranslate"><span class="pre">virtualenv</span></code> for every project you work on).</p>
<p>When a <code class="docutils literal notranslate"><span class="pre">virtualenv</span></code> is active, all you have to do is use the <code class="docutils literal notranslate"><span class="pre">deactivate</span></code>
command:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">(</span>demoenv<span class="o">)</span>$ deactivate
$ which python
/usr/bin/python
</pre></div>
</div>
<p>Note that your shell prompt returns to normal, and now the executable Python
found when you check <code class="docutils literal notranslate"><span class="pre">python</span></code> is the system one again.</p>
</div>
<div class="section" id="cleaning-up">
<h3>Cleaning Up<a class="headerlink" href="#cleaning-up" title="Permalink to this headline">¶</a></h3>
<p>The final great advantage that <code class="docutils literal notranslate"><span class="pre">virtualenv</span></code> confers on you as a developer is
the ability to easily remove a batch of installed Python software from your
system. Consider a situation where you installed a library that breaks your
Python (it happens). If you are working in your system Python, you now have to
figure out what that package installed, where, and go clean it out manually.
With <code class="docutils literal notranslate"><span class="pre">virtualenv</span></code> the process is as simple as removing the directory that
virtualenv created when you started out. Let’s do that with our <code class="docutils literal notranslate"><span class="pre">demoenv</span></code>:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ rm -rf demoenv
</pre></div>
</div>
<p>And that’s it. The entire environment and all the packages you installed into
it are now gone. There’s no traces left to pollute your world.</p>
</div>
</div>
<div class="section" id="virtualenvwrapper">
<h2>VirtualenvWrapper<a class="headerlink" href="#virtualenvwrapper" title="Permalink to this headline">¶</a></h2>
<p>So you have this great tool that allows you to build isolated environments in
which you can install Python software. Several questions arise when considering
this.</p>
<ul class="simple">
<li><p>Where should such environments be placed?</p></li>
<li><p>How can the environments be tied to the projects you are working on?</p></li>
<li><p>Once you have more than a trivial number of projects, how can you keep track
of all these virtualenvs?</p></li>
</ul>
<p>Like any good tool, <code class="docutils literal notranslate"><span class="pre">virtualenv</span></code> does not impose on you any particular way of
working. You can place your environments into the directories where you are
building the project to which they apply. You can keep them all in a single
global location. You can build a random path generator that drops them
wherever.</p>
<p>But any of these methods lead inevetably to chaos. They require too much from
you. It would be better if you could manage your virtual environments easily
and intuitively.</p>
<p>With <a class="reference external" href="http://virtualenvwrapper.readthedocs.org">virtualenvwrapper</a> you can.</p>
<div class="section" id="installation">
<h3>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h3>
<p>Let’s start by installing the package in our system Python, alongside
<code class="docutils literal notranslate"><span class="pre">virtualenv</span></code> (again, you’ll need <code class="docutils literal notranslate"><span class="pre">superuser</span></code> to do this):</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ sudo pip install virtualenvwrapper
Downloading/unpacking virtualenvwrapper
Downloading virtualenvwrapper-4.2.tar.gz <span class="o">(</span>125kB<span class="o">)</span>: 125kB downloaded
Running setup.py <span class="o">(</span>path:/private/tmp/pip_build_root/virtualenvwrapper/setup.py<span class="o">)</span> egg_info <span class="k">for</span> package virtualenvwrapper
...
Successfully installed virtualenvwrapper virtualenv-clone stevedore
Cleaning up...
$
</pre></div>
</div>
<p>Once that’s finished, you’ll need to wire the system up by letting your shell
know that the commands it provides are present. Add the following lines to your
shell startup file (<code class="docutils literal notranslate"><span class="pre">.profile</span></code>, <code class="docutils literal notranslate"><span class="pre">.bash-profile</span></code>, …):</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">export</span> <span class="nv">WORKON_HOME</span><span class="o">=</span>~/.virtualenvs
<span class="nb">source</span> /usr/local/bin/virtualenvwrapper.sh
</pre></div>
</div>
<p>This will create a new environmental variable, <code class="docutils literal notranslate"><span class="pre">WORKON_HOME</span></code>, that determines
where new virtual environments will be created. The actual name is completely
arbitrary.</p>
<p>You’ll need to be sure that the location you set exists:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ mkdir ~/.virtualenvs
</pre></div>
</div>
</div>
<div class="section" id="using-mkvirtualenv">
<h3>Using <code class="docutils literal notranslate"><span class="pre">mkvirtualenv</span></code><a class="headerlink" href="#using-mkvirtualenv" title="Permalink to this headline">¶</a></h3>
<p>When you’ve done that, start a new terminal and you’ll have access to the
<code class="docutils literal notranslate"><span class="pre">mkvirtualenv</span></code> command:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ mkvirtualenv testenv
New python executable in testenv/bin/python
Installing setuptools, pip...done.
<span class="o">(</span>testenv<span class="o">)</span>$ ls ~/.virtualenvs
testenv
<span class="o">(</span>testenv<span class="o">)</span>$ which python
/Users/cewing/.virtualenvs/testenv/bin/python
<span class="o">(</span>testenv<span class="o">)</span>$
</pre></div>
</div>
<p>Notice a couple of things:</p>
<ul class="simple">
<li><p>The new environment you asked for was created in <code class="docutils literal notranslate"><span class="pre">WORKON_HOME</span></code></p></li>
<li><p>The new environment was <em>immedately</em> activated for you</p></li>
</ul>
<p>That’s a nice feature, eh? No more needing to remember to <code class="docutils literal notranslate"><span class="pre">activate</span></code> the env
you just created to install packages.</p>
</div>
<div class="section" id="using-workon">
<h3>Using <code class="docutils literal notranslate"><span class="pre">workon</span></code><a class="headerlink" href="#using-workon" title="Permalink to this headline">¶</a></h3>
<p>In addition to this nice little feature, you can also use the <code class="docutils literal notranslate"><span class="pre">workon</span></code>
command to see which environments you have, and to switch from one to another:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">(</span>testenv<span class="o">)</span>$ workon
testenv
<span class="o">(</span>testenv<span class="o">)</span>$ mkvirtualenv number2
New python executable in number2/bin/python
Installing setuptools, pip...done.
<span class="o">(</span>number2<span class="o">)</span>$ workon
number2
testenv
<span class="o">(</span>number2<span class="o">)</span>$ workon testenv
<span class="o">(</span>testenv<span class="o">)</span>$
</pre></div>
</div>
<p>Sweet!</p>
<p>The same <code class="docutils literal notranslate"><span class="pre">deactivate</span></code> command can get you back to your system environment:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">(</span>testenv<span class="o">)</span>$ deactivate
$
</pre></div>
</div>
</div>
<div class="section" id="using-mkproject">
<h3>Using <code class="docutils literal notranslate"><span class="pre">mkproject</span></code><a class="headerlink" href="#using-mkproject" title="Permalink to this headline">¶</a></h3>
<p>That takes care of deciding where to put new environments. It also clears up
the question of how to remember which ones you have and how to start them up
and switch between them. But we still have to figure out how to remember which
environment goes with which project.</p>
<p>That’s what the <code class="docutils literal notranslate"><span class="pre">mkproject</span></code> command is for.</p>
<p>First, go back to your shell startup file and add a new environmental variable:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">export</span> <span class="nv">PROJECT_HOME</span><span class="o">=</span>~/projects <span class="c1">#<- this line here is new</span>
<span class="nb">export</span> <span class="nv">WORKON_HOME</span><span class="o">=</span>~/.virtualenvs
<span class="nb">source</span> /usr/local/bin/virtualenvwrapper.sh
</pre></div>
</div>
<p>Then, make sure the directory you named exists:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ mkdir ~/projects
</pre></div>
</div>
<p>After all that, fire up a new shell to pick up the changes and try this:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ mkproject foo
New python executable in foo/bin/python
Installing setuptools, pip...done.
Creating /Users/cewing/projects/foo
Setting project <span class="k">for</span> foo to /Users/cewing/projects/foo
<span class="o">(</span>foo<span class="o">)</span>$ which python
/Users/cewing/.virtualenvs/foo/bin/python
<span class="o">(</span>foo<span class="o">)</span>$ <span class="nb">pwd</span>
/Users/cewing/projects/foo
<span class="o">(</span>foo<span class="o">)</span>$ ls -a <span class="nv">$VIRTUAL_ENV</span>
. .Python bin lib
.. .project include
<span class="o">(</span>foo<span class="o">)</span>$ more <span class="nv">$VIRTUAL_ENV</span>/.project
/Users/cewing/projects/foo
</pre></div>
</div>
<p>Whoa! That command did a lot:</p>
<ul class="simple">
<li><p>Created a new <code class="docutils literal notranslate"><span class="pre">virtualenv</span></code> in your <code class="docutils literal notranslate"><span class="pre">$WORKON_HOME</span></code></p></li>
<li><p>Created a new project directory in your <code class="docutils literal notranslate"><span class="pre">$PROJECT_HOME</span></code></p></li>
<li><p>Placed a <code class="docutils literal notranslate"><span class="pre">.project</span></code> file in your home directory with a path leading to the
associated project directory</p></li>
<li><p>Activated the new virtualenv for you</p></li>
<li><p>Automatically moved your present working directory to the new project
directory.</p></li>
</ul>
<p>And now, you can begin working on your <code class="docutils literal notranslate"><span class="pre">foo</span></code> project, secure that you will be
installing packages into the right environment.</p>
</div>
</div>
<div class="section" id="a-few-last-words">
<h2>A Few Last Words<a class="headerlink" href="#a-few-last-words" title="Permalink to this headline">¶</a></h2>
<p>This quick introduction is <strong>by no means</strong> an exhaustive manual for either of
the packages we’ve talked about. There is a great deal more that they can do.
In particular, <code class="docutils literal notranslate"><span class="pre">virtualenvwrapper</span></code> is highly customizable, with support for
custom scripts to be hooked into every stage of the <code class="docutils literal notranslate"><span class="pre">virtualenv</span></code> workflow.</p>
<p>I urge you to read the documentation for <a class="reference external" href="http://www.virtualenv.org/">virtualenv</a> and <a class="reference external" href="http://virtualenvwrapper.readthedocs.org">virtualenvwrapper</a>
yourself to find out more.</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>