I'm currently toying with python at home and I'm planning to switch to python 3.1. The fact is that I have some script that use python 2.6 and I can't convert them since they use some module that aren't available for python 3.1 atm. So I'm considering installing python 3.1 along my python 2.6. I only found people on internet that achieve that by compiling python from source and use make altinstall
instead of the classic make install
. Anyway, I think compiling from source is a bit complicated. I thought running two different version of a program is easy on linux (I run fedora 11 for the record). Any hint?
我现在正在玩家里的python,我打算切换到python 3.1。事实是我有一些使用python 2.6的脚本,我无法转换它们,因为它们使用了一些不适用于python 3.1 atm的模块。所以我正在考虑在我的python 2.6上安装python 3.1。我只发现互联网上的人通过从源代码编译python并使用make altinstall而不是经典的make install来实现这一点。无论如何,我认为从源代码编译有点复杂。我认为在linux上运行两个不同版本的程序很简单(我运行fedora 11作为记录)。任何提示?
Thanks for reading.
谢谢阅读。
4 个解决方案
#1
On my Linux system (Ubuntu Jaunty), I have Python 2.5, 2.6 and 3.0 installed, just by installing the binary (deb) packages 'python2.5', 'python2.6' and 'python3.0' using apt-get. Perhaps Fedora packages them and names them as RPMs in a similar way.
在我的Linux系统(Ubuntu Jaunty)上,我安装了Python 2.5,2.6和3.0,只需使用apt-get安装二进制(deb)软件包'python2.5','python2.6'和'python3.0'。也许Fedora打包它们并以类似的方式将它们命名为RPM。
I can run the one I need from the command line just by typing e.g. python2.6
. So I can also specify the one I want at the top of my script by putting e.g.:
我可以通过输入例如命令行从命令行运行我需要的那个python2.6的。所以我也可以通过放置例如:在我的脚本顶部指定我想要的那个:
#!/usr/bin/python2.6
#2
Download the python version you want to have as an alternative, untar it, and when you configure it, use --prefix=/my/alt/dir
下载你想要的python版本,解压缩它,当你配置它时,使用--prefix = / my / alt / dir
Cheers
Nik
#3
You're not supposed to need to run them together.
你不应该一起运行它们。
2.6 already has all of the 3.0 features. You can enable those features with from __future__ import
statements.
2.6已经拥有所有3.0功能。您可以使用__future__ import语句启用这些功能。
It's much simpler run 2.6 (with some from __future__ import
) until everything you need is in 3.x, then switch.
运行2.6(有一些来自__future__ import)要简单得多,直到你需要的是3.x,然后切换。
#4
Why do you need to use make install
at all? After having done make
to compile python 3.x, just move the python folder somewhere, and create a symlink to the python executable in your ~/bin
directory. Add that directory to your path if it isn't already, and you'll have a working python development version ready to be used. As long as the symlink itself is not named python (I've named mine py
), you'll never experience any *es.
为什么你需要使用make install?完成编译python 3.x之后,只需将python文件夹移动到某处,然后在〜/ bin目录中创建一个符号链接到python可执行文件。将该目录添加到您的路径中(如果尚未添加),您将可以使用正在运行的python开发版本。只要符号链接本身没有命名为python(我已经命名为我的py),你就永远不会遇到任何冲突。
An added benefit is that if you want to change to a new release of python 3.x, for example if you're following the beta releases, you simply download, compile and replace the folder with the new one.
另一个好处是,如果您想要更新到python 3.x的新版本,例如,如果您正在关注测试版,那么您只需下载,编译并用新版本替换该文件夹。
It's slightly messy, but the messiness is confined to one directory, and I find it much more convenient than thinking about altinstalls and the like.
它有点凌乱,但是混乱局限于一个目录,我发现它比考虑altinstalls等更方便。
#1
On my Linux system (Ubuntu Jaunty), I have Python 2.5, 2.6 and 3.0 installed, just by installing the binary (deb) packages 'python2.5', 'python2.6' and 'python3.0' using apt-get. Perhaps Fedora packages them and names them as RPMs in a similar way.
在我的Linux系统(Ubuntu Jaunty)上,我安装了Python 2.5,2.6和3.0,只需使用apt-get安装二进制(deb)软件包'python2.5','python2.6'和'python3.0'。也许Fedora打包它们并以类似的方式将它们命名为RPM。
I can run the one I need from the command line just by typing e.g. python2.6
. So I can also specify the one I want at the top of my script by putting e.g.:
我可以通过输入例如命令行从命令行运行我需要的那个python2.6的。所以我也可以通过放置例如:在我的脚本顶部指定我想要的那个:
#!/usr/bin/python2.6
#2
Download the python version you want to have as an alternative, untar it, and when you configure it, use --prefix=/my/alt/dir
下载你想要的python版本,解压缩它,当你配置它时,使用--prefix = / my / alt / dir
Cheers
Nik
#3
You're not supposed to need to run them together.
你不应该一起运行它们。
2.6 already has all of the 3.0 features. You can enable those features with from __future__ import
statements.
2.6已经拥有所有3.0功能。您可以使用__future__ import语句启用这些功能。
It's much simpler run 2.6 (with some from __future__ import
) until everything you need is in 3.x, then switch.
运行2.6(有一些来自__future__ import)要简单得多,直到你需要的是3.x,然后切换。
#4
Why do you need to use make install
at all? After having done make
to compile python 3.x, just move the python folder somewhere, and create a symlink to the python executable in your ~/bin
directory. Add that directory to your path if it isn't already, and you'll have a working python development version ready to be used. As long as the symlink itself is not named python (I've named mine py
), you'll never experience any *es.
为什么你需要使用make install?完成编译python 3.x之后,只需将python文件夹移动到某处,然后在〜/ bin目录中创建一个符号链接到python可执行文件。将该目录添加到您的路径中(如果尚未添加),您将可以使用正在运行的python开发版本。只要符号链接本身没有命名为python(我已经命名为我的py),你就永远不会遇到任何冲突。
An added benefit is that if you want to change to a new release of python 3.x, for example if you're following the beta releases, you simply download, compile and replace the folder with the new one.
另一个好处是,如果您想要更新到python 3.x的新版本,例如,如果您正在关注测试版,那么您只需下载,编译并用新版本替换该文件夹。
It's slightly messy, but the messiness is confined to one directory, and I find it much more convenient than thinking about altinstalls and the like.
它有点凌乱,但是混乱局限于一个目录,我发现它比考虑altinstalls等更方便。