|
5 | 5 | ----------
|
6 | 6 | 问题
|
7 | 7 | ----------
|
8 |
| -You want to install a third-party package, but you don’t have permission to install packages |
9 |
| -into the system Python. Alternatively, perhaps you just want to install a package |
10 |
| -for your own use, not all users on the system. |
| 8 | +你想要安装一个第三方包,但是没有权限将它安装到系统Python库中去。 |
| 9 | +或者,你可能想要安装一个供自己使用的包,而不是系统上面所有用户。 |
11 | 10 |
|
12 | 11 | ----------
|
13 | 12 | 解决方案
|
14 | 13 | ----------
|
15 |
| -Python has a per-user installation directory that’s typically located in a directory such |
16 |
| -as ~/.local/lib/python3.3/site-packages. To force packages to install in this directory, give |
17 |
| -the --user option to the installation command. For example: |
| 14 | +Python有一个用户安装目录,通常类似"~/.local/lib/python3.3/site-packages"。 |
| 15 | +要强制在这个目录中安装包,可使用安装选项“--user”。例如: |
18 | 16 |
|
19 | 17 | .. code-block:: python
|
20 | 18 |
|
21 | 19 | python3 setup.py install --user
|
22 | 20 |
|
23 |
| -or |
| 21 | +或者 |
24 | 22 |
|
25 | 23 | .. code-block:: python
|
26 | 24 |
|
27 | 25 | pip install --user packagename
|
28 | 26 |
|
29 |
| -The user site-packages directory normally appears before the system site-packages directory |
30 |
| -on sys.path. Thus, packages you install using this technique take priority over |
31 |
| -the packages already installed on the system (although this is not always the case depending |
32 |
| -on the behavior of third-party package managers, such as distribute or pip). |
| 27 | +在sys.path中用户的“site-packages”目录位于系统的“site-packages”目录之前。 |
| 28 | +因此,你安装在里面的包就比系统已安装的包优先级高 |
| 29 | +(尽管并不总是这样,要取决于第三方包管理器,比如distribute或pip)。 |
| 30 | + |
33 | 31 |
|
34 | 32 | ----------
|
35 | 33 | 讨论
|
36 | 34 | ----------
|
37 |
| -Normally, packages get installed into the system-wide site-packages directory, which is |
38 |
| -found in a location such as /usr/local/lib/python3.3/site-packages. However, doing so |
39 |
| -typically requires administrator permissions and use of the sudo command. Even if you |
40 |
| -have permission to execute such a command, using sudo to install a new, possibly unproven, |
41 |
| -package might give you some pause. |
42 |
| - |
43 |
| - |
44 |
| -Installing packages into the per-user directory is often an effective workaround that |
45 |
| -allows you to create a custom installation. |
46 |
| - |
| 35 | +通常包会被安装到系统的site-packages目录中去,路径类似“/usr/local/lib/python3.3/site-packages”。 |
| 36 | +不过,这样做需要有管理员权限并且使用sudo命令。 |
| 37 | +就算你有这样的权限去执行命令,使用sudo去安装一个新的,可能没有被验证过的包有时候也不安全。 |
47 | 38 |
|
48 |
| -As an alternative, you can also create a virtual environment, which is discussed in the |
49 |
| -next recipe. |
| 39 | +安装包到用户目录中通常是一个有效的方案,它允许你创建一个自定义安装。 |
50 | 40 |
|
| 41 | +另外,你还可以创建一个虚拟环境,这个我们在下一节会讲到。 |
0 commit comments