同一台机器上有多个 Python 版本? [英] Multiple Python versions on the same machine?

查看:51
本文介绍了同一台机器上有多个 Python 版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 网站上有没有关于如何在 Linux 上的同一台机器上安装和运行多个版本的 Python 的官方文档?

Is there official documentation on the Python website somewhere, on how to install and run multiple versions of Python on the same machine on Linux?

我可以找到无数的博文和答案,但我想知道是否有一种标准"的官方方法来做到这一点?

I can find gazillions of blog posts and answers, but I want to know if there is a "standard" official way of doing this?

或者这完全取决于操作系统?

Or is this all dependent on OS?

推荐答案

我认为它是完全独立的.只需安装它们,然后您就可以使用命令,例如/usr/bin/python2.5/usr/bin/python2.6.将 /usr/bin/python 链接到您要用作默认值的那个.

I think it is totally independent. Just install them, then you have the commands e.g. /usr/bin/python2.5 and /usr/bin/python2.6. Link /usr/bin/python to the one you want to use as default.

无论如何,所有库都在单独的文件夹中(以版本命名).

All the libraries are in separate folders (named after the version) anyway.

如果你想手动编译版本,这是来自 Python 源代码的自述文件:

If you want to compile the versions manually, this is from the readme file of the Python source code:

安装多个版本

在 Unix 和 Mac 系统上,如果您打算安装多个版本的 Python使用相同的安装前缀(配置的 --prefix 参数脚本)你必须注意你的主要 python 可执行文件不是被不同版本的安装覆盖.所有文件和使用make altinstall"安装的目录包含主要和次要版本,因此可以并排生活.make install"也创建${prefix}/bin/python3 指的是 ${prefix}/bin/pythonX.Y.如果你打算要使用相同的前缀安装多个版本,您必须决定哪个版本(如果有)是您的主要"版本.使用安装该版本进行安装".使用make altinstall"安装所有其他版本.

On Unix and Mac systems if you intend to install multiple versions of Python using the same installation prefix (--prefix argument to the configure script) you must take care that your primary python executable is not overwritten by the installation of a different version. All files and directories installed using "make altinstall" contain the major and minor version and can thus live side-by-side. "make install" also creates ${prefix}/bin/python3 which refers to ${prefix}/bin/pythonX.Y. If you intend to install multiple versions using the same prefix you must decide which version (if any) is your "primary" version. Install that version using "make install". Install all other versions using "make altinstall".

例如,如果要安装 Python 2.5、2.6 和 3.0,其中 2.6 是主要版本,您将在 2.6 版本中执行make install"目录和其他目录中的make altinstall".

For example, if you want to install Python 2.5, 2.6 and 3.0 with 2.6 being the primary version, you would execute "make install" in your 2.6 build directory and "make altinstall" in the others.

这篇关于同一台机器上有多个 Python 版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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