Skip to content

Commit c542e8d

Browse files
committed
10.14小节完成
1 parent 677edb2 commit c542e8d

File tree

1 file changed

+21
-33
lines changed

1 file changed

+21
-33
lines changed

source/c10/p14_creating_new_python_environment.rst

+21-33
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,21 @@
55
----------
66
问题
77
----------
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环境产生影响。
1110

1211
----------
1312
解决方案
1413
----------
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目录中。下面是一个例子:
1816

1917
.. code-block:: python
2018
2119
bash % pyvenv Spam
2220
bash %
2321
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目录像下面这样:
2623

2724
.. code-block:: python
2825
@@ -31,7 +28,7 @@ creation, the Spam directory will look something like this:
3128
bin include lib pyvenv.cfg
3229
bash %
3330
34-
In the bin directory, you’ll find a Python interpreter that you can use. For example:
31+
在bin目录中,你会找到一个可以使用的Python解释器:
3532

3633
.. code-block:: python
3734
@@ -50,41 +47,32 @@ In the bin directory, you’ll find a Python interpreter that you can use. For e
5047
'/Users/beazley/Spam/lib/python3.3/site-packages']
5148
>>>
5249
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目录。
5652
5753
----------
5854
讨论
5955
----------
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目录已经被重定位到一个新的目录。
6459
60+
有了一个新的虚拟环境,下一步就是安装一个包管理器,比如distribute或pip。
61+
但安装这样的工具和包的时候,你需要确保你使用的是虚拟环境的解释器。
62+
它会将包安装到新创建的site-packages目录中去。
6563
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+
因此,创建这样的环境是很容易的,并且几乎不会消耗机器资源。
7068
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”选项来创建虚拟环境,例如:
8171
8272
.. code-block:: python
8373
8474
bash % pyvenv --system-site-packages Spam
8575
bash %
8676
87-
More information about pyvenv and virtual environments can be found in
77+
跟多关于 ``pyvenv`` 和虚拟环境的信息可以参考
8878
`PEP 405 <https://www.python.org/dev/peps/pep-0405/>`_.
89-
90-

0 commit comments

Comments
 (0)