不同python版本的apt-get安装 [英] apt-get install for different python versions

查看:83
本文介绍了不同python版本的apt-get安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我默认使用 ubuntu 10.04 和 python2.6.我已经安装了python2.7.

I have ubuntu 10.04 with python2.6 by default. I have installed python2.7.

当我想用

apt-get python-<package> 

它被安装到 python2.6.我如何才能将软件包安装到 python2.7?有什么选择吗?

it gets installed to python2.6. How can I make it to install the package to python2.7? Is there any option?

我查看了this,但在我的操作系统中找不到此类目录.我曾考虑使用 easy_install-2.7,但并非所有软件包都受支持.例如 python-torctl.

I have looked at this, but I could not find such directories in my OS. I have considered using easy_install-2.7, but not all packages are supported. For example python-torctl.

我更感兴趣的是将 python2.7 与 apt-get install 绑定.

I am more interested in binding python2.7 with apt-get install.

推荐答案

Python 拥有自己的包管理工具,与 Linux 发行版(包括 Ubuntu)的一套并行.存储库是 Pypi - Python 包索引,包使用 pip 或 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.

这篇关于不同python版本的apt-get安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆