-
Notifications
You must be signed in to change notification settings - Fork 0
/
PythonVirtualEnv.html
623 lines (281 loc) · 23.9 KB
/
PythonVirtualEnv.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
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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
<!DOCTYPE HTML>
<html lang="zh-hans" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Python虚拟环境 · 大数据技术与算法Checklist</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<meta name="author" content="powerlee">
<link rel="stylesheet" href="gitbook/style.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-search-pro/search.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-prism/prism.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-splitter/splitter.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-back-to-top-button/plugin.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-advanced-emoji/emoji-website.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-insert-logo/plugin.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-pageview-count/plugin.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-flexible-alerts/style.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-katex-new/katex.min.css">
<link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-theme-comscore/test.css">
<link rel="stylesheet" href="styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="SparkLocalInstall.html" />
<link rel="prev" href="ProbabilityAndStatistics.html" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="输入并搜索" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="1.1" data-path="./">
<a href="./">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="GradientDescent.html">
<a href="GradientDescent.html">
梯度下降
</a>
</li>
<li class="chapter " data-level="1.3" data-path="LinearRegression.html">
<a href="LinearRegression.html">
线性回归
</a>
</li>
<li class="chapter " data-level="1.4" data-path="LogisticRegression.html">
<a href="LogisticRegression.html">
逻辑回归
</a>
</li>
<li class="chapter " data-level="1.5" data-path="DecisionTree.html">
<a href="DecisionTree.html">
决策树
</a>
</li>
<li class="chapter " data-level="1.6" data-path="ABTest.html">
<a href="ABTest.html">
A/B实验
</a>
</li>
<li class="chapter " data-level="1.7" data-path="TimeSeries.html">
<a href="TimeSeries.html">
时间序列
</a>
</li>
<li class="chapter " data-level="1.8" data-path="DimensionalModeling.html">
<a href="DimensionalModeling.html">
维度建模
</a>
</li>
<li class="chapter " data-level="1.9" data-path="UserBehaviorsAnalysisPlatform.html">
<a href="UserBehaviorsAnalysisPlatform.html">
用户行为分析平台
</a>
</li>
<li class="chapter " data-level="1.10" data-path="SQLKeypoints.html">
<a href="SQLKeypoints.html">
SQL要点
</a>
</li>
<li class="chapter " data-level="1.11" data-path="SQLCases.html">
<a href="SQLCases.html">
SQL案例
</a>
</li>
<li class="chapter " data-level="1.12" data-path="Kafka.md">
<span>
Kafka
</a>
</li>
<li class="chapter " data-level="1.13" data-path="Spark.html">
<a href="Spark.html">
Spark
</a>
</li>
<li class="chapter " data-level="1.14" data-path="Flink.md">
<span>
Flink
</a>
</li>
<li class="chapter " data-level="1.15" data-path="ClickHouse.md">
<span>
ClickHouse
</a>
</li>
<li class="chapter " data-level="1.16" data-path="ProbabilityAndStatistics.html">
<a href="ProbabilityAndStatistics.html">
概率论与数理统计
</a>
</li>
<li class="chapter active" data-level="1.17" data-path="PythonVirtualEnv.html">
<a href="PythonVirtualEnv.html">
Python虚拟环境
</a>
</li>
<li class="chapter " data-level="1.18" data-path="SparkLocalInstall.html">
<a href="SparkLocalInstall.html">
Spark本地安装部署
</a>
</li>
<li class="chapter " data-level="1.19" data-path="GitCheatSheet.html">
<a href="GitCheatSheet.html">
Git Cheat Sheet
</a>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
本书使用 GitBook 发布
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="." >Python虚拟环境</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h2 id="venv">venv</h2>
<p>在 python3.3 之前,需要通过 virtualenv 创建虚拟环境,首先需要<strong>安装 virtualenv</strong></p>
<pre class="language-"><code class="lang-bash">$ pip <span class="token function">install</span> virtualenv
</code></pre>
<p><strong>创建虚拟环境</strong></p>
<pre class="language-"><code class="lang-bash"><span class="token comment"># 当前目录创建一个myvenv的文件夹,并在文件夹下创建虚拟环境</span>
<span class="token comment"># 参数--no-site-packages的意思是创建虚拟环境时,不复制主环境中已安装的包,而是创建一个“干净的”虚拟环境</span>
$ virtualenv --no-site-packages myvenv
<span class="token comment"># 指定一个Python解释器</span>
$ virtualenv <span class="token parameter variable">-p</span> /usr/bin/python2.8 myvenv
</code></pre>
<p><strong>进入虚拟环境</strong></p>
<pre class="language-"><code class="lang-bash"><span class="token comment"># 进入需要使用的虚拟环境的上层目录,运行activate</span>
$ <span class="token builtin class-name">source</span> ./myvenv/bin/activate
</code></pre>
<p><strong>退出虚拟环境</strong></p>
<pre class="language-"><code class="lang-bash"><span class="token comment"># 在虚拟环境中,需要退出只需要输入deactivate</span>
<span class="token punctuation">(</span>myvenv<span class="token punctuation">)</span> $ deactivate
</code></pre>
<p><strong>删除虚拟环境</strong></p>
<pre class="language-"><code class="lang-bash"><span class="token comment"># 只需要删除虚拟环境所在的目录即可</span>
$ <span class="token function">rm</span> –r myvenv
</code></pre>
<p>Python3.3 之后,可以用python自带的 venv 模块创建虚拟环境。除创建虚拟环境意外,<strong>其它跟virtualenv完全一致</strong>。</p>
<p><strong>创建虚拟环境</strong></p>
<pre class="language-"><code class="lang-bash"><span class="token comment"># 当前目录创建一个myvenv的文件夹,并在文件夹下创建虚拟环境</span>
$ python <span class="token parameter variable">-m</span> venv myvenv
</code></pre>
<h2 id="conda">conda</h2>
<p>如果安装了Anaconda,可以用conda创建虚拟环境。</p>
<p><strong>创建虚拟环境</strong></p>
<pre class="language-"><code class="lang-bash"><span class="token comment"># 在Anaconda安装目录下的envs文件夹下创建名为myvenv目录,并在该目录下创建虚拟环境,同时设定该虚拟环境的python版本</span>
$ conda create <span class="token parameter variable">-n</span> myvenv <span class="token assign-left variable">python</span><span class="token operator">=</span>x.x
</code></pre>
<p><strong>切换至某个虚拟环境</strong></p>
<pre class="language-"><code class="lang-bash"><span class="token comment"># 切换至名为yourenv的虚拟环境</span>
$ conda activate yourenv
$ <span class="token builtin class-name">source</span> activate yourenv <span class="token comment"># source也可以</span>
</code></pre>
<p><strong>退出某个虚拟环境</strong></p>
<pre class="language-"><code class="lang-bash"><span class="token comment"># 在某个虚拟环境下键入以下命令退出虚拟环境</span>
<span class="token punctuation">(</span>yourenv<span class="token punctuation">)</span> $ conda deactivate
<span class="token punctuation">(</span>yourenv<span class="token punctuation">)</span> $ <span class="token builtin class-name">source</span> deactivate <span class="token comment"># 高版本Anaconda可能无法使用</span>
</code></pre>
<p><strong>查看当前存在的虚拟环境</strong></p>
<pre class="language-"><code class="lang-bash">$ conda <span class="token function">env</span> list
$ conda info <span class="token parameter variable">-e</span>
</code></pre>
<p><strong>虚拟环境安装包</strong></p>
<pre class="language-"><code class="lang-bash"><span class="token comment"># 为myvenv虚拟环境安装numpy</span>
$ conda <span class="token function">install</span> <span class="token parameter variable">-n</span> myvenv numpy
<span class="token comment"># 也可以先进入该虚拟环境,直接在虚拟环境下安装</span>
<span class="token punctuation">(</span>yourenv<span class="token punctuation">)</span> $ conda <span class="token function">install</span> numpy
</code></pre>
<p><strong>删除虚拟环境</strong></p>
<pre class="language-"><code class="lang-bash">$ conda remove <span class="token parameter variable">--name</span> myvenv <span class="token parameter variable">--all</span>
</code></pre>
<p><strong>查看当前环境安装的包</strong></p>
<pre class="language-"><code class="lang-bash">$ conda list
</code></pre>
<p><strong>查看镜像源channels</strong></p>
<pre class="language-"><code class="lang-bash">$ conda config <span class="token parameter variable">--get</span> channels
</code></pre>
<p><strong>添加镜像源</strong></p>
<pre class="language-"><code class="lang-bash">$ conda config <span class="token parameter variable">--add</span> channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
</code></pre>
<p><strong>删除镜像源</strong></p>
<pre class="language-"><code class="lang-bash">$ conda config <span class="token parameter variable">--remove</span> channels channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
</code></pre>
<div id="gitalk-container"></div>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="ProbabilityAndStatistics.html" class="navigation navigation-prev " aria-label="Previous page: 概率论与数理统计">
<i class="fa fa-angle-left"></i>
</a>
<a href="SparkLocalInstall.html" class="navigation navigation-next " aria-label="Next page: Spark本地安装部署">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"Python虚拟环境","level":"1.17","depth":1,"next":{"title":"Spark本地安装部署","level":"1.18","depth":1,"path":"SparkLocalInstall.md","ref":"SparkLocalInstall.md","articles":[]},"previous":{"title":"概率论与数理统计","level":"1.16","depth":1,"path":"ProbabilityAndStatistics.md","ref":"ProbabilityAndStatistics.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","search-pro","-code","-codeline","-highlight","prism","expandable-chapters","chapter-fold","splitter","back-to-top-button","advanced-emoji","hide-element","insert-logo","custom-favicon","pageview-count","-sharing","sharing-plus","flexible-alerts","katex-new","mygitalk","theme-comscore","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"chapter-fold":{},"prism":{},"styles":{"website":"website.css","ebook":"ebook.css","pdf":"pdf.css","mobi":"ebook.css","epub":"ebook.css"},"katex-new":{},"livereload":{},"splitter":{},"search-pro":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"hide-element":{"elements":[".gitbook-link"]},"fontsettings":{"theme":"white","family":"sans","size":2},"favicon":"pics/logo.ico","theme-comscore":{},"back-to-top-button":{},"pageview-count":{},"custom-favicon":{},"flexible-alerts":{"style":"callout","note":{"label":"Note","icon":"fa fa-info-circle","className":"info"},"tip":{"label":"Tip","icon":"fa fa-lightbulb-o","className":"tip"},"warning":{"label":"Warning","icon":"fa fa-exclamation-triangle","className":"warning"},"danger":{"label":"Attention","icon":"fa fa-ban","className":"danger"}},"mygitalk":{"flipMoveOptions":{},"clientID":"c623ce11cb38fa65e5f0","number":-1,"perPage":10,"proxy":"https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token","admin":["powerAmore"],"createIssueManually":false,"distractionFreeMode":false,"repo":"DataSciChecklist","owner":"powerAmore","enableHotKey":true,"clientSecret":"09a234dcf2ca63822ea9858aa00245147624e61d","pagerDirection":"last","labels":["Gitalk"]},"advanced-emoji":{"embedEmojis":false},"sharing":{"facebook":true,"twitter":true,"all":["douban","facebook","google","twitter","weibo","qq","whatsapp"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"insert-logo":{"url":"pics/logo.jpeg","style":"background: none; max-height: 30px; min-height: 30px"},"expandable-chapters":{}},"theme":"default","author":"powerlee","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"大数据技术与算法Checklist","language":"zh-hans","links":{},"gitbook":"*","description":"大数据技术与算法Checklist"},"file":{"path":"PythonVirtualEnv.md","mtime":"2023-01-29T14:13:14.120Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-02-04T03:57:06.860Z"},"basePath":".","book":{"language":""}});
});
</script>
</div>
<script src="gitbook/gitbook.js"></script>
<script src="gitbook/theme.js"></script>
<script src="gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
<script src="gitbook/gitbook-plugin-search-pro/search.js"></script>
<script src="gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
<script src="gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
<script src="gitbook/gitbook-plugin-splitter/splitter.js"></script>
<script src="gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
<script src="gitbook/gitbook-plugin-hide-element/plugin.js"></script>
<script src="gitbook/gitbook-plugin-insert-logo/plugin.js"></script>
<script src="gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
<script src="gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
<script src="gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
<script src="https://cdn.bootcss.com/blueimp-md5/2.12.0/js/md5.min.js"></script>
<script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
<script src="gitbook/gitbook-plugin-mygitalk/mygitalk.js"></script>
<script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
<script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="gitbook/gitbook-plugin-theme-comscore/test.js"></script>
</body>
</html>