5
5
----------
6
6
问题
7
7
----------
8
- You want to create a new Python environment in which you can install modules and
9
- packages. However, you want to do this without installing a new copy of Python or
10
- making changes that might affect the system Python installation.
8
+ 你想创建一个新的Python环境,用来安装模块和包。
9
+ 不过,你不想安装一个新的Python克隆,也不想对系统Python环境产生影响。
11
10
12
11
----------
13
12
解决方案
14
13
----------
15
- You can make a new “virtual” environment using the pyvenv command. This command
16
- is installed in the same directory as the Python interpreter or possibly in the Scripts
17
- directory on Windows. Here is an example:
14
+ 你可以使用 ``pyvenv `` 命令创建一个新的“虚拟”环境。
15
+ 这个命令被安装在Python解释器同一目录,或Windows上面的Scripts目录中。下面是一个例子:
18
16
19
17
.. code-block :: python
20
18
21
19
bash % pyvenv Spam
22
20
bash %
23
21
24
- The name supplied to pyvenv is the name of a directory that will be created. Upon
25
- creation, the Spam directory will look something like this:
22
+ 传给 ``pyvenv `` 命令的名字是将要被创建的目录名。当被创建后,Span目录像下面这样:
26
23
27
24
.. code-block :: python
28
25
@@ -31,7 +28,7 @@ creation, the Spam directory will look something like this:
31
28
bin include lib pyvenv.cfg
32
29
bash %
33
30
34
- In the bin directory, you’ll find a Python interpreter that you can use. For example:
31
+ 在bin目录中,你会找到一个可以使用的Python解释器:
35
32
36
33
.. code-block :: python
37
34
@@ -50,41 +47,32 @@ In the bin directory, you’ll find a Python interpreter that you can use. For e
50
47
' /Users/beazley/Spam/lib/python3.3/site-packages' ]
51
48
>> >
52
49
53
- A key feature of this interpreter is that its site- packages directory has been set to the
54
- newly created environment. Should you decide to install third- party packages, they will
55
- be installed here, not in the normal system site- packages directory.
50
+ 这个解释器的特点就是他的site- packages目录被设置为新创建的环境。
51
+ 如果你要安装第三方包,它们会被安装在那里,而不是通常系统的site- packages目录。
56
52
57
53
----------
58
54
讨论
59
55
----------
60
- The creation of a virtual environment mostly pertains to the installation and management
61
- of third-party packages. As you can see in the example, the sys.path variable
62
- contains directories from the normal system Python, but the site-packages directory has
63
- been relocated to a new directory.
56
+ 创建虚拟环境通常是为了安装和管理第三方包。
57
+ 正如你在例子中看到的那样,`` sys.path`` 变量包含来自于系统Python的目录,
58
+ 而 site- packages目录已经被重定位到一个新的目录。
64
59
60
+ 有了一个新的虚拟环境,下一步就是安装一个包管理器,比如distribute或pip。
61
+ 但安装这样的工具和包的时候,你需要确保你使用的是虚拟环境的解释器。
62
+ 它会将包安装到新创建的site- packages目录中去。
65
63
66
- With a new virtual environment, the next step is often to install a package manager,
67
- such as distribute or pip. When installing such tools and subsequent packages, you
68
- just need to make sure you use the interpreter that’s part of the virtual environment.
69
- This should install the packages into the newly created site-packages directory.
64
+ 尽管一个虚拟环境看上去是Python安装的一个复制,
65
+ 不过它实际上只包含了少量几个文件和一些符号链接。
66
+ 素有标准库函文件和可执行解释器都来自原来的Python安装。
67
+ 因此,创建这样的环境是很容易的,并且几乎不会消耗机器资源。
70
68
71
-
72
- Although a virtual environment might look like a copy of the Python installation, it
73
- really only consists of a few files and symbolic links. All of the standard library files and
74
- interpreter executables come from the original Python installation. Thus, creating such
75
- environments is easy, and takes almost no machine resources.
76
-
77
-
78
- By default, virtual environments are completely clean and contain no third-party addons.
79
- If you would like to include already installed packages as part of a virtual environment,
80
- create the environment using the --system-site-packages option. For example:
69
+ 默认情况下,虚拟环境是空的,不包含任何额外的第三方库。如果你想将一个已经安装的包作为虚拟环境的一部分,
70
+ 可以使用“-- system- site- packages”选项来创建虚拟环境,例如:
81
71
82
72
.. code- block:: python
83
73
84
74
bash % pyvenv -- system- site- packages Spam
85
75
bash %
86
76
87
- More information about pyvenv and virtual environments can be found in
77
+ 跟多关于 `` pyvenv`` 和虚拟环境的信息可以参考
88
78
`PEP 405 < https:// www.python.org/ dev/ peps/ pep- 0405 / > ` _.
89
-
90
-
0 commit comments