简体   繁体   English

在CentOS中安装python 2.6

[英]Install python 2.6 in CentOS

I have a shell that runs CentOS. 我有一个运行CentOS的shell。

For a project I'm doing, I need python 2.5+, but centOS is pretty dependent on 2.4. 对于我正在做的项目,我需要python 2.5+,但centOS非常依赖于2.4。

From what I've read, a number of things will break if you upgrade to 2.5. 根据我的阅读,如果你升级到2.5,很多事情都会破裂。

I want to install 2.5 separately from 2.4, but I'm not sure how to do it. 我想从2.4分开安装2.5,但我不知道该怎么做。 So far I've downloaded the source tarball, untarred it, and did a ./configure --prefix=/opt which is where I want it to end up. 到目前为止,我已经下载了源代码tarball,解压缩它,然后执行了./configure --prefix=/opt这是我希望它最终结束的地方。 Can I now just make, make install ? 我现在可以make, make install吗? Or is there more? 或者还有更多?

您也可以使用EPEL-repository ,然后执行sudo yum install python26来安装python 2.6

Try epel 试试epel

wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
sudo rpm -ivh epel-release-5-4.noarch.rpm
sudo yum install python26

The python executable will be available at /usr/bin/python26 python可执行文件将在/usr/bin/python26

mkdir -p ~/bin
ln -s /usr/bin/python26 ~/bin/python
export PATH=~/bin:$PATH # Append this to your ~/.bash_profile for persistence

Now, python command will execute python 2.6 现在, python命令将执行python 2.6

When I've run into similar situations, I generally avoid the package manager, especially if it would be embarrassing to break something, ie a production server. 当我遇到类似情况时,我通常会避免使用软件包管理器,特别是如果要破坏某些东西(即生产服务器)会很尴尬。 Instead, I would go to Activestate and download their binary package: 相反,我会去Activestate并下载他们的二进制包:

https://www.activestate.com/activepython/downloads/ https://www.activestate.com/activepython/downloads/

This is installed by running a script which places everything into a folder and does not touch any system files. 这是通过运行脚本来安装的,该脚本将所有内容放入文件夹中,而不会触及任何系统文件。 In fact, you don't even need root permissions to set it up. 实际上,您甚至不需要root权限来设置它。 Then I change the name of the binary to something like apy26, add that folder to the end of the PATH and start coding. 然后我将二进制文件的名称更改为apy26,将该文件夹添加到PATH的末尾并开始编码。 If you install packages with apy26 setup.py install or if you use virtualenv and easyinstall, then you have just as flexible a python environment as you need without touching the system standard python. 如果您使用apy26 setup.py install安装软件包,或者如果您使用virtualenv和easyinstall,那么您可以根据需要灵活地设置python环境,而无需触及系统标准python。

Edits... Recently I've done some work to build a portable Python binary for Linux that should run on any distro with no external dependencies. 编辑...最近我做了一些工作来为Linux构建一个可移植的Python二进制文件,它应该在没有外部依赖关系的任何发行版上运行。 This means that any binary shared libraries needed by the portable Python module are part of the build, included in the tarball and installed in Python's private directory structure. 这意味着可移植Python模块所需的任何二进制共享库都是构建的一部分,包含在tarball中并安装在Python的私有目录结构中。 This way you can install Python for your application without interfering with the system installed Python. 这样,您可以为应用程序安装Python,而不会干扰系统安装的Python。

My github site has a build script which has been thoroughly tested on Ubuntu Lucid 10.04 LTS both 32 and 64 bit installs. 我的github网站有一个构建脚本,已经在Ubuntu Lucid 10.04 LTS上进行了全面的32位和64位安装测试。 I've also built it on Debian Etch but that was a while ago and I can't guarantee that I haven't changed something. 我也是在Debian Etch上构建的,但是不久之前我无法保证我没有改变某些东西。 The easiest way to do this is you just put your choice of Ubuntu Lucid in a virtual machine, checkout the script with git clone git://github.com/wavetossed/pybuild.git and then run the script. 最简单的方法是将Ubuntu Lucid选择放在虚拟机中,使用git clone git://github.com/wavetossed/pybuild.git检查脚本,然后运行脚本。

Once you have it built, use the tarball on any recent Linux distro. 构建完成后,在任何最新的Linux发行版上使用tarball。 There is one little wrinkle with moving it to a directory other than /data1/packages/python272 which is that you have to run the included patchelf to set the interpreter path BEFORE you move the directory. 将一个目录移动到/data1/packages/python272 patchelf以外的目录中有一点小皱纹,即在移动目录之前必须运行包含的patchelf来设置解释器路径。 This affects any binaries in /data1/packages/python272/bin 这会影响/data1/packages/python272/bin任何二进制文件

All of this is based on building with RUNPATH and copying the dependent shared libraries. 所有这些都基于使用RUNPATH构建并复制依赖的共享库。 Even though the script is in several files, it is effectively one long shell script arranged in the style of /etc/rc.d directories. 即使脚本在几个文件中,它实际上是一个以/etc/rc.d目录的样式排列的长shell脚本。

No need to do yum or make your own RPM. 无需做百胜或制作自己的RPM。 Build python26 from source. 从源代码构建python26

wget https://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
tar -zxvf Python-2.6.6.tgz
cd Python-2.6.6
./configure && make && make install

There can be a dependency error use 可能存在依赖性错误使用

yum install gcc cc

Add the install path ( /usr/local/bin/python by default) to ~/.bash_profile . 将安装路径(默认情况下为/usr/local/bin/python )添加到~/.bash_profile

It will not break yum or any other things which are dependent on python24 . 它不会破坏yum或依赖于python24任何其他东西。

No, that's it. 不,就是这样。 You might want to make sure you have all optional library headers installed too so you don't have to recompile it later. 您可能希望确保已安装所有可选库头文件,以便以后不必重新编译它。 They are listed in the documentation I think. 它们列在我认为的文档中。

Also, you can install it even in the standard path if you do make altinstall . 此外,如果您确实make altinstall ,即使在标准路径中也可以安装它。 That way it won't override your current default "python". 这样它就不会覆盖你当前的默认“python”。

Chris Lea provides a YUM repository for python26 RPMs that can co-exist with the 'native' 2.4 that is needed for quite a few admin tools on CentOS. Chris Lea为python26 RPMs提供了一个YUM存储库,它可以与CentOS上的很多管理工具所需的“本机”2.4共存。

Quick instructions that worked at least for me: 至少对我有用的快速说明:

$ sudo rpm -Uvh http://yum.chrislea.com/centos/5/i386/chl-release-5-3.noarch.rpm
$ sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CHL
$ sudo yum install python26
$ python26

If you want to make it easier on yourself, there are CentOS RPMs for new Python versions floating around the net. 如果你想让自己更容易,那么CentOS RPM就会出现在网络上的新Python版本。 Eg see: 例如,见:

http://www.geekymedia.com/python_26_centos.html http://www.geekymedia.com/python_26_centos.html

当你安装你的python版本(在这种情况下它是python2.6)然后发出此命令来创建你的virtualenv

virtualenv -p /usr/bin/python2.6 /your/virtualenv/path/here/

Late to the party, but the OP should have gone with Buildout or Virtualenv , and sidestepped the problem completely. 晚到派对,但OP应该与BuildoutVirtualenv一起 ,并完全回避问题。

I am currently working on a Centos server, well, toiling away would be the proper term and I can assure everyone that the only way I am able to blink back the tears whilst using the software equivalents of fire hardened spears, is buildout. 我目前正在使用Centos服务器,好吧,辛苦工作将是正确的术语,我可以向所有人保证,在使用防火硬化矛的软件时,我能够眨眼泪的唯一方法是扩建。

# yum groupinstall "Development tools"
# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel

Download and install Python 3.3.0 下载并安装Python 3.3.0

# wget http://python.org/ftp/python/3.3.0/Python-3.3.0.tar.bz2
# tar xf Python-3.3.0.tar.bz2
# cd Python-3.3.0
# ./configure --prefix=/usr/local
# make && make altinstall

Download and install Distribute for Python 3.3 下载并安装Distribute for Python 3.3

# wget http://pypi.python.org/packages/source/d/distribute/distribute-0.6.35.tar.gz
# tar xf distribute-0.6.35.tar.gz
# cd distribute-0.6.35
# python3.3 setup.py install

Install and use virtualenv for Python 3.3 安装并使用适用于Python 3.3的virtualenv

# easy_install-3.3 virtualenv
# virtualenv-3.3 --distribute otherproject

New python executable in otherproject/bin/python3.3
Also creating executable in otherproject/bin/python
Installing distribute...................done.
Installing pip................done.

# source otherproject/bin/activate
# python --version
Python 3.3.0
rpm -Uvh http://yum.chrislea.com/centos/5/i386/chl-release-5-3.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CHL
rpm -Uvh ftp://ftp.pbone.net/mirror/centos.karan.org/el5/extras/testing/i386/RPMS/libffi-3.0.5-1.el5.kb.i386.rpm
yum install python26
python26

for dos that just dont know :=) 对于那些不知道的东西:=)

I unistalled the original version of python (2.6.6) and install 2.7(with option make && make altinstall ) but when I tried install something with yum didn't work. 我取消了原始版本的python(2.6.6)并安装了2.7(使用选项make && make altinstall )但是当我尝试使用yum安装时没有用。

So I solved this issue as follow: 所以我解决了这个问题如下:

  1. # ln -s /usr/local/bin/python /usr/bin/python
  2. Download the RPM package python-2.6.6-36.el6.i686.rpm from http://rpm.pbone.net/index.php3/stat/4/idpl/20270470/dir/centos_6/com/python-2.6.6-36.el6.i686.rpm.html http://rpm.pbone.net/index.php3/stat/4/idpl/20270470/dir/centos_6/com/python-2.6下载RPM软件包python-2.6.6-36.el6.i686.rpm 。 6-36.el6.i686.rpm.html
  3. Execute as root rpm -Uvh python-2.6.6-36.el6.i686.rpm 以root身份执行rpm -Uvh python-2.6.6-36.el6.i686.rpm

Done 完成

Type the following commands on the terminal to install Python 3.6 on CentOS 7: 在终端上键入以下命令以在CentOS 7上安装Python 3.6:

$ sudo yum install https://centos7.iuscommunity.org/ius-release.rpm

Then do : 然后做 :

$ sudo yum install python36u 

You can also install any version instead of 3.6 (if you want to) by just replacing 36 by your version number. 您也可以安装任何版本而不是3.6(如果您愿意),只需用版本号替换36即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM