且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

不同python版本的apt-get安装

更新时间:2023-02-02 20:44:30

Python 拥有自己的包管理工具,与 Linux 发行版(包括 Ubuntu)的一套并行.存储库是 Pypi - Python 包索引,包使用 pip安装a> 或 easy_install 脚本,它是 Python 的 setuptools 包的一部分.

Python has got its own package managing facilities, in parallel to the one sets by the Linux distributions (including Ubuntu). The repository is the Pypi - Python Package Index, and packages are installed with pip or the easy_install script, which is part of Python's setuptools package.

根据经验,您不应同时使用通过 pip/setuptools 安装的软件包和发行版可用的软件包(通过 apt-get、yum、urpmi 等),因为它们可能会发生冲突.

As a rule of thumb, you should not use both the packages installed via pip/setuptools, and packages available to your distro (via apt-get, yum, urpmi, etc...) as they might conflict.

因此,处理它的一种不太容易出错的方法是在您的系统中安装单独的 Python - 将系统随附的 Python 留给系统脚本等 - 在此 Python 上,利用安装的软件包仅限您的包管理器.并安装其他版本的 Python(或什至相同),以使用virtualenv"运行 - 在这些其他安装中,您仅使用 pip/setuptools 安装东西.

So, one of the less error prone way to deal with it is to have separate Python installs in your system - leave the python that came with the system for system scripts and such - on this python, make use of packages installed by your package manager only. And install other versions of Python (or even the same), to be run with "virtualenv"s - on these other install you install things with pip/setuptools only.

(即使有人选择大胆地生活而不使用 virtualenvs,在相同的前缀上安装另一个 python 版本(/usr,甚至 /usr/local)比您系统的 Python 更容易混淆错误和冲突).

(And even if one opt to live boldly and not use virtualenvs, installing another python version on the same prefix (/usr, and even /usr/local) than your system's Python is a source to confusing errors and conflicts).

请注意,Debian 和 Ubuntu 系统设计了一种在/usr 中运行并行官方 Python 的方法,并让 apt-get 一次将 Python 包安装到两个 Python 版本.这在大多数情况下有效,但它们与 Python 的默认目录层次结构混乱,并且某些应用程序无法以这种方式使用 Python.(在 Debian 或 Ubuntu 中查找模块文件本身也是一团糟).因此,即使您的系统在 apt-get 上确实有多个可用的 Python 版本,上述方法仍作为建议适用.

Note that the Debian - and Ubuntu - systems devised a way to run parallel official Python's in /usr, and to have apt-get to install Python packages to both Python versions at once. This mostly works, but they mess with Python's default directory hierarchy, and some applications fail to use Python in this way. (It is also a mess to find the module files themselves in a Debian or Ubuntu). So the above method apply as a recommendation even if your system do have more than one version of Python available on apt-get.

简而言之,一旦您编译了所需的 Python 版本,请执行以下操作:

In short, once you have compiled your desired version of Python, do this:

  1. 使用系统的包管理器安装python-setuptools"和python-virtualenv"(不确定这些是否是实际的包名).
  2. 使用 virtualenv 创建一个环境,您将在其中使用不同的 Python 版本
  3. 激活您的 virtualenv,并在其上使用 pip 安装 Python 包.
  1. use your system's package manager to install "python-setuptools" and "python-virtualenv" (not sure if these are the actual package names).
  2. Use virtualenv to create an environment from which you will use your different Python version
  3. Activate your virtualenv, and install Python packages using pip on it.

Virtualenv 确实有一个--help"开关来帮助你,但你基本上是这样做的:

Virtualenv does feature a "--help" switch to help you, but you basically do:

$ virtualenv -p <path-to-python-interpreter>  <environment-dir>
$ source <environment-dir>/bin/activate

你就是这样 - 由于设置了环境变量,所有使用 Python 的东西都将看到"virtualenv 中的解释器.

And there you are - all things using Python will "see" the interpreter in the virtualenv, due to environment variables set.