Linux 不同python版本的apt-get安装
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10960805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
apt-get install for different python versions
提问by torayeff
I have ubuntu 10.04 with python2.6 by default. I have installed python2.7.
默认情况下,我有 ubuntu 10.04 和 python2.6。我已经安装了python2.7。
When I want to install python packages with
当我想安装 python 包时
apt-get python-<package>
it gets installed to python2.6. How can I make it to install the package to python2.7? Is there any option?
它被安装到python2.6。我如何才能将软件包安装到 python2.7?有什么选择吗?
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
.
我看过这个,但在我的操作系统中找不到这样的目录。我曾考虑使用easy_install-2.7
,但并非所有软件包都受支持。例如python-torctl
。
I am more interested in binding python2.7 with apt-get install
.
我更感兴趣的是将 python2.7 与apt-get install
.
采纳答案by jsbueno
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.
Python 有自己的包管理工具,与 Linux 发行版(包括 Ubuntu)的一套并行。存储库是 Pypi - Python 包索引,包是使用pip
或 easy_install 脚本安装的,它是 Python 的 setuptools 包的一部分。
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.
根据经验,您不应同时使用通过 pip/setuptools 安装的软件包和发行版可用的软件包(通过 apt-get、yum、urpmi 等),因为它们可能会发生冲突。
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.
因此,处理它的一种不太容易出错的方法是在您的系统中安装单独的 Python - 将系统随附的 Python 留给系统脚本等 - 在此 Python 上,使用您的软件包管理器安装的软件包只要。并安装其他版本的 Python(或什至相同),以使用“virtualenv”运行 - 在这些其他安装中,您仅使用 pip/setuptools 安装东西。
(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).
(即使人们选择大胆地生活而不使用 virtualenvs,在与系统 Python相同的前缀(/usr
, 甚至/usr/local
)上安装另一个 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.
请注意,Debian 和 Ubuntu 系统设计了一种在 /usr 中运行并行官方 Python 的方法,并使用 apt-get 将 Python 包同时安装到两个 Python 版本。这主要是有效的,但它们会干扰 Python 的默认目录层次结构,并且某些应用程序无法以这种方式使用 Python。(在 Debian 或 Ubuntu 中查找模块文件本身也是一团糟)。因此,即使您的系统在 apt-get 上确实有多个可用的 Python 版本,上述方法仍可作为推荐使用。
In short, once you have compiled your desired version of Python, do this:
简而言之,一旦您编译了所需的 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.
- 使用系统的包管理器安装“python-setuptools”和“python-virtualenv”(不确定这些是否是实际的包名)。
- 使用
virtualenv
创建从中您将使用不同的Python版本的环境 - 激活您的 virtualenv,并使用
pip
它安装 Python 包。
Virtualenv does feature a "--help" switch to help you, but you basically do:
Virtualenv 确实有一个“--help”开关来帮助你,但你基本上是这样做的:
$ virtualenv -p <path-to-python-interpreter> <environment-dir>
$ source <environment-dir>/bin/activate
And there you are - all things using Python will "see" the interpreter in the virtualenv, due to environment variables set.
你就是这样 - 由于设置了环境变量,所有使用 Python 的东西都会在 virtualenv 中“看到”解释器。
回答by dm03514
ubuntu 10.04 doesn't have a python2.7 package. You have to build 2.7 yourself. I did read an article about ubuntu releasing a python2.7 package when 12.04 came out but i'm not sure what the repository location is.
ubuntu 10.04 没有 python2.7 包。您必须自己构建 2.7。我确实读过一篇关于 ubuntu 在 12.04 发布时发布 python2.7 包的文章,但我不确定存储库位置是什么。
http://eli.thegreenplace.net/2011/10/10/installing-python-2-7-on-ubuntu/
http://eli.thegreenplace.net/2011/10/10/installing-python-2-7-on-ubuntu/
or:
或者:
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.7
https://askubuntu.com/questions/101591/install-python-2-7-2-on-ubuntu-10-04-64-bit
https://askubuntu.com/questions/101591/install-python-2-7-2-on-ubuntu-10-04-64-bit
this question has lots of answers online.
这个问题网上有很多答案。