在 linux SUSE 或 RedHat 上,如何加载 Python 2.7

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4149361/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:50:24  来源:igfitidea点击:

On linux SUSE or RedHat, how do I load Python 2.7

pythonlinuxrhelsuse

提问by Dag

Can someone provide the steps needed to install python version 2.7 on SUSE and RedHat? It version that is on there is like 2.4 and I need to have it at at least 2.6 to make my script work. So after the install, I can type Python in a xTerm and get the Python 2.7 command line interface.

有人可以提供在 SUSE 和 RedHat 上安装 python 2.7 版所需的步骤吗?那里的版本就像 2.4,我需要至少 2.6 才能使我的脚本工作。因此,安装后,我可以在 xTerm 中键入 Python 并获得 Python 2.7 命令行界面。

采纳答案by dr jimbob

Instructions to download source and install:

下载源码和安装说明:

https://www.python.org/download/

https://www.python.org/download/

NOTE: You should check for the latest version of python 2.7.x, as it gets updated frequently. Currently (Oct 2017), the latest version is 2.7.14 though this comment will get old and new versions likely will be released every 6 months or so.

注意:您应该检查 python 2.7.x 的最新版本,因为它经常更新。目前(2017 年 10 月),最新版本是 2.7.14,尽管此评论会变旧,新版本可能每 6 个月左右发布一次。

wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz # Download
tar xvfz Python-2.7.14.tgz # unzip
cd Python-2.7.14 # go into directory
./configure
make # build
su # or 'sudo su' if there is no root user
make altinstall

(EDIT: make install -> make altinstall per Ignacio's comment).

(编辑:make install -> make altinstall 根据 Ignacio 的评论)。

回答by g19fanatic

Great thing about linux, you're still able to download the sourceand on most systems have all of the tools to compile the version yourself.

linux 的一大优点是,您仍然可以下载源代码,并且在大多数系统上都有自己编译版本的所有工具。

In order to get a python cli from xterm just by typing python, the python bin directory must be in your system path variable (Red Hat example, Suse example)

为了仅通过键入从 xterm 获取 python cli python,python bin 目录必须在您的系统路径变量中(Red Hat 示例Suse 示例

回答by Ignacio Vazquez-Abrams

If you can live with 2.6, EPELhas it for RHEL 5 in the python26package, although you will need to use python2.6to invoke it since the system will still need pythonto be 2.4 in order to run.

如果您可以使用 2.6,则EPELpython26软件包中为 RHEL 5 提供了它,尽管您需要使用python2.6它来调用它,因为系统仍需要python为 2.4 才能运行。

回答by Christophe

You have to leave Python 2.4 installed on RHEL/Centos; otherwise, tools start breaking. You can do a dual-install, though; I talk about this here:

你必须在 RHEL/Centos 上安装 Python 2.4;否则,工具开始损坏。不过,您可以进行双重安装;我在这里谈这个:

http://thebuild.com/blog/2009/10/17/wordpress-to-djangopostgresql-part-3-installing-apache-python-2-6-psycopg2-and-mod_wsgi/

http://thebuild.com/blog/2009/10/17/wordpress-to-djangopostgresql-part-3-installing-apache-python-2-6-psycopg2-and-mod_wsgi/

The post is about 2.6, but applies equally to 2.7.

该职位大约为 2.6,但同样适用于 2.7。

回答by Sudheer

To install Python 2.7.2 use this script - https://github.com/bngsudheer/bangadmin/blob/master/linux/centos/6/x86_64/build-python-27.sh

要安装 Python 2.7.2,请使用此脚本 - https://github.com/bngsudheer/bangadmin/blob/master/linux/centos/6/x86_64/build-python-27.sh

It also makes sure you get sqlite and readline support.

它还确保您获得 sqlite 和 readline 支持。

回答by Rob Fisher

The accepted answer by dr jimbob (using make altinstall) got me most of the way there, with python2.7in /usr/local/binbut I also needed to install some third party modules. The nice thing is that easy_install gets its installation locations from the version of Python you are running, but I found I still needed to install easy_install for Python 2.7 otherwise I would get ImportError: No module named pkg_resources. So I did this:

jimbob 博士(使用make altinstall)接受的答案让我在那里完成了大部分工作python2.7/usr/local/bin但我还需要安装一些第三方模块。好消息是 easy_install 从您正在运行的 Python 版本获取其安装位置,但我发现我仍然需要为 Python 2.7 安装 easy_install 否则我会得到ImportError: No module named pkg_resources. 所以我这样做了:

wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
sudo -i
export PATH=$PATH:/usr/local/bin
sh setuptools-0.6c11-py2.7.egg
exit

Now I have easy_installand easy_install-2.7in /usr/local/bin and the former overrides my system's 2.6 version of easy_install, so I removed it:

现在我已经easy_installeasy_install-2.7在/ usr / local / bin目录和前覆盖我的系统的2.6版中的easy_install,所以我删除它:

sudo rm /usr/local/bin/easy_install

Now I can install libraries for the 2.7 version of Python like this:

现在我可以像这样为 2.7 版本的 Python 安装库:

sudo /usr/local/bin/easy_install-2.7 numpy

回答by Rob Fisher

RHEL 6.2using (had Python 2.6, i need Python 2.7.3) So:

RHEL 6.2使用(有 Python 2.6,我需要Python 2.7.3)所以:

$ sudo sh -c 'wget -qO- http://people.redhat.com/bkabrda/scl_python27.repo >> /etc/yum.repos.d/scl.repo'

$ yum search python27
Loaded plugins: amazon-id, rhui-lb, security
scl_python27                                                                                                                                      | 2.9 kB     00:00     
scl_python27/primary_db                                                                                                                           |  38 kB     00:00     
========================================================================= N/S Matched: python27 =========================================================================
python27.i686 : Package that installs python27
python27.x86_64 : Package that installs python27
python27-expat-debuginfo.i686 : Debug information for package python27-expat
python27-expat-debuginfo.x86_64 : Debug information for package python27-expat
python27-python-coverage-debuginfo.i686 : Debug information for package python27-python-coverage
python27-python-coverage-debuginfo.x86_64 : Debug information for package python27-python-coverage
python27-python-debuginfo.i686 : Debug information for package python27-python
python27-python-debuginfo.x86_64 : Debug information for package python27-python
python27-python-markupsafe-debuginfo.i686 : Debug information for package python27-python-markupsafe
python27-python-markupsafe-debuginfo.x86_64 : Debug information for package python27-python-markupsafe
python27-python-simplejson-debuginfo.i686 : Debug information for package python27-python-simplejson
python27-python-simplejson-debuginfo.x86_64 : Debug information for package python27-python-simplejson
python27-python-sqlalchemy-debuginfo.i686 : Debug information for package python27-python-sqlalchemy
python27-python-sqlalchemy-debuginfo.x86_64 : Debug information for package python27-python-sqlalchemy
python27-runtime.i686 : Package that handles python27 Software Collection.
python27-runtime.x86_64 : Package that handles python27 Software Collection.
python27-babel.noarch : Tools for internationalizing Python applications
python27-build.i686 : Package shipping basic build configuration
python27-build.x86_64 : Package shipping basic build configuration
python27-expat.i686 : An XML parser library
python27-expat.x86_64 : An XML parser library
python27-expat-devel.i686 : Libraries and header files to develop applications using expat
python27-expat-devel.x86_64 : Libraries and header files to develop applications using expat
python27-expat-static.i686 : expat XML parser static library
python27-expat-static.x86_64 : expat XML parser static library
python27-python.i686 : An interpreted, interactive, object-oriented programming language
python27-python.x86_64 : An interpreted, interactive, object-oriented programming language
python27-python-babel.noarch : Library for internationalizing Python applications
python27-python-coverage.i686 : Code coverage testing module for Python
python27-python-coverage.x86_64 : Code coverage testing module for Python
python27-python-debug.i686 : Debug version of the Python runtime
python27-python-debug.x86_64 : Debug version of the Python runtime
python27-python-devel.i686 : The libraries and header files needed for Python development
python27-python-devel.x86_64 : The libraries and header files needed for Python development
python27-python-docutils.noarch : System for processing plaintext documentation
python27-python-jinja2.noarch : General purpose template engine
python27-python-libs.i686 : Runtime libraries for Python
python27-python-libs.x86_64 : Runtime libraries for Python
python27-python-markupsafe.i686 : Implements a XML/HTML/XHTML Markup safe string for Python
python27-python-markupsafe.x86_64 : Implements a XML/HTML/XHTML Markup safe string for Python
python27-python-nose.noarch : Discovery-based unittest extension for Python
python27-python-nose-docs.noarch : Nose Documentation
python27-python-pygments.noarch : Syntax highlighting engine written in Python
python27-python-setuptools.noarch : Easily build and distribute Python packages
python27-python-simplejson.i686 : Simple, fast, extensible JSON encoder/decoder for Python
python27-python-simplejson.x86_64 : Simple, fast, extensible JSON encoder/decoder for Python
python27-python-sphinx.noarch : Python documentation generator
python27-python-sphinx-doc.noarch : Documentation for python-sphinx
python27-python-sqlalchemy.i686 : Modular and flexible ORM library for python
python27-python-sqlalchemy.x86_64 : Modular and flexible ORM library for python
python27-python-test.i686 : The test modules from the main python package
python27-python-test.x86_64 : The test modules from the main python package
python27-python-tools.i686 : A collection of development tools included with Python
python27-python-tools.x86_64 : A collection of development tools included with Python
python27-python-virtualenv.noarch : Tool to create isolated Python environments
python27-python-werkzeug.noarch : The Swiss Army knife of Python web development
python27-python-werkzeug-doc.noarch : Documentation for python-werkzeug
python27-tkinter.i686 : A graphical user interface for the Python scripting language
python27-tkinter.x86_64 : A graphical user interface for the Python scripting language

  Name and summary matches only, use "search all" for everything.

EDIT:

编辑:

CentOS 6.x: http://dev.centos.org/centos/6/SCL/x86_64/python27/

$ sudo sh -c 'wget -qO- http://dev.centos.org/centos/6/SCL/scl.repo >> /etc/yum.repos.d/scl.repo'
$ scl enable python27 'python --version'
python 2.7.5
$ scl enable python27 bash
$ python --version
Python 2.7.5

回答by Shahrukh Khan

Execute the below commands to make yum work as well as python2.7

执行以下命令使 yum 和 python2.7 一样工作

yum groupinstall -y development
yum groupinstall -y 'development tools'
yum install -y zlib-dev openssl-devel wget sqlite-devel bzip2-devel
yum -y install gcc gcc-c++ numpy python-devel scipy git boost*
yum install -y *lapack*
yum install -y gcc gcc-c++ make bison flex autoconf libtool memcached libevent libevent-devel uuidd libuuid-devel  boost boost-devel libcurl-dev libcurl curl gperf mysql-devel

cd
mkdir srk
cd srk 
wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
yum install xz-libs
xz -d Python-2.7.6.tar.xz
tar -xvf Python-2.7.6.tar
cd Python-2.7.6
./configure --prefix=/usr/local
make
make altinstall



echo "export PATH="/usr/local/bin:$PATH"" >> /etc/profile
source /etc/profile
mv /usr/bin/python /usr/bin/python.bak
update-alternatives --install /usr/bin/python python /usr/bin/python2.6 1
update-alternatives --install /usr/bin/python python /usr/local/bin/python2.7 2
update-alternatives --config python
sed -i "s/python/python2.6/g" /usr/bin/yum

回答by Alex Punnen

If you need pip and setup tool , please install openssl and opessl-devl before making python2.7

如果需要pip和安装工具,请在制作python2.7之前安装openssl和opessl-devl

 yum install openssl-devel

Then follow https://stackoverflow.com/a/4149444/429476

然后按照https://stackoverflow.com/a/4149444/429476

Then https://pypi.python.org/pypi/setuptools

然后https://pypi.python.org/pypi/setuptools

wget https://bootstrap.pypa.io/ez_setup.py
python2.7 ez_setup.py

Then to install pip

然后安装pip

wget https://bootstrap.pypa.io/get-pip.py
python2.7 get-pip.py

Then to install other packages pip2.7 install package_name

然后安装其他包 pip2.7 install package_name

回答by Adriano R P L

If you want to install Python 2.7 on Oracle Linux, you can proceed as follows:

如果要在 Oracle Linux 上安装 Python 2.7,可以按以下步骤操作:

Enable the Software Collection in /etc/yum.repos.d/public-yum-ol6.repo.

在 /etc/yum.repos.d/public-yum-ol6.repo 中启用软件集合。

vim /etc/yum.repos.d/public-yum-ol6.repo

[public_ol6_software_collections] 
name=Software Collection Library release 1.2 packages for Oracle Linux 6 
(x86_64) 
baseurl=[http://yum.oracle.com/repo/OracleLinux/OL6/SoftwareCollections12/x86_64/][1] 
    gpgkey=file:[///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle][2] 
    gpgcheck=1 
    enabled=1 <==============change from 0 to 1

After making this change to the yum repository you can simply run the yum command to install the Python:

对 yum 存储库进行此更改后,您只需运行 yum 命令即可安装 Python:

yum install gcc libffi libffi-devel python27 python27-python-devel openssl-devel python27-MySQL-python

edit bash_profile with follow variables:

使用以下变量编辑 bash_profile:

vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/opt/rh/python27/root/usr/bin export PATH
LD_LIBRARY_PATH=/opt/rh/python27/root/usr/lib64 export LD_LIBRARY_PATH
PKG_CONFIG_PATH=/opt/rh/python27/root/usr/lib64/pkgconfig export PKG_CONFIG_PATH

Now you can use python2.7 and pip for install Python modules:

现在你可以使用 python2.7 和 pip 来安装 Python 模块了:

/opt/rh/python27/root/usr/bin/pip install pynacl
/opt/rh/python27/root/usr/bin/python2.7 --version