问题描述
默认情况下,我具有python2.6的ubuntu 10.04.我已经安装了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?
我查看了此,但是在我的操作系统中找不到这样的目录.我已经考虑过使用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上,使用由安装的软件包仅您的包裹管理员.并安装要与"virtualenv"一起运行的其他版本的Python(甚至相同版本)-在其他安装方式中,您只能使用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的方法,并且可以轻松地同时将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:
- 使用系统的软件包管理器安装"python-setuptools"和"python-virtualenv"(不确定它们是否为实际的软件包名称).
- 使用
virtualenv
创建一个环境,在该环境中您将使用不同的Python版本 - 激活您的virtualenv,并使用
pip
在其上安装Python软件包.
- use your system's package manager to install "python-setuptools" and "python-virtualenv" (not sure if these are the actual package names).
- Use
virtualenv
to create an environment from which you will use your different Python version - 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.
这篇关于apt-get install适用于不同的python版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!