CentOS6.5上安装Python2.7和PIP

目前大部分用户使用的CentOS6.5上默认的Python还是2.6版本。升级到Python2.7碰到很多问题。本文将介绍如何安装Python2.7。

1. 安装必要的准备包

安装过程将用到gcc,方便起见,安装“Development Tools”

yum groupinstall "Development tools"

另外,Python安装中需要的一些依赖包

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel

2. 下载安装Python2.7

目前Python2.7的最新版本是2.7.11。可以在下面的网站查询:

https://www.python.org/ftp/python/

2.7.11的下载链接是:

https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz

wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgztar vxf Python-2.7.11.tgzcd Python-2.7.11.tgz./configure --prefix=/usr/localmake && make install

  安装完成后,通过运行python,可以看到版本

>>> import sys
>>> sys.version
‘2.7.11 (default, May  6 2016, 01:38:00) \n[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)]‘

3.安装pip

  pip是python的安装工具,很多python的常用工具,都可以通过pip进行安装。

  要安装pip,首先要安装setuptools。下面的链接可以得到相关信息,最新版本是21.0.0:

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

  下载链接:

  https://pypi.python.org/packages/ff/d4/209f4939c49e31f5524fa0027bf1c8ec3107abaf7c61fdaad704a648c281/setuptools-21.0.0.tar.gz#md5=81964fdb89534118707742e6d1a1ddb4

  同样的,进行安装:

tar vxf setuptools-21.0.0.tar.gz
cd setuptools-21.0.0
python setup.py  install

  安装完成后,下载pip。其信息在如下网站:

  https://pypi.python.org/pypi/pip

  最新版是8.1.1,下载链接:

  https://pypi.python.org/packages/41/27/9a8d24e1b55bd8c85e4d022da2922cb206f183e2d18fee4e320c9547e751/pip-8.1.1.tar.gz#md5=6b86f11841e89c8241d689956ba99ed7

  同样的,进行安装

tar vxf pip-8.1.1.tar.gz
cd pip-8.1.1
python setup.py install

  安装完成后,运行pip

[[email protected] pip-8.1.1]# pip

Usage:
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output.
  --log <path>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form [user:[email protected]]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.
  --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don‘t periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
[[email protected] pip-8.1.1]# 

  安装一个程序检测:

[[email protected] pip-8.1.1]# pip install psutil
Collecting psutil
  Downloading psutil-4.1.0.tar.gz (301kB)
    100% |████████████████████████████████| 307kB 274kB/s
Installing collected packages: psutil
  Running setup.py install for psutil ... done
Successfully installed psutil-4.1.0

4. 载入常用的tab.py程序

#!/usr/bin/evn python
import sys
import readline
import rlcompleter
import atexit
import os
readline.parse_and_bind(‘tab: complete‘)
histfile = os.path.join(os.environ[‘HOME‘], ‘.pythonhistory‘)
try:
   readline.read_history_file(histfile)
except IOError:
   pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter

时间: 2024-10-20 13:22:08

CentOS6.5上安装Python2.7和PIP的相关文章

CentOS6.6上安装Python2.7.10

CenoOS6.6 64位系统默认的Python版本是2.6.6,工作中需要使用Python2.7.10.本文介绍一下Python2.7.10的安装方法.切记:不可覆盖Python2.6.6,小心你的系统不能用了.总的来说安装过程是:Python2.7.10源码安装---->setuptools16.0安装---->pip安装 Python2.7.10源码安装预安装 yum groupinstall "Development tools";yum install zlib-

如何在CentOS6上安装Python2.7和Python3.3

原文来自http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/,个人觉得对在linux安装新版本Python是很有参考意义,因而转载,原文是英文的,本人简单翻译下,大家看懂即可,有不妥的地方请留言. 如何在CentOS 6上同时安装Python 2.7和Python 3.3 本文将介绍如何在CentOS 6上安装Python 2.7和3.3.下面以Python 2.7.6和Python 3.3.5为例进行说明,但本人实

CentOS5.5上安装Python2.7及ez_setup和pip包

CentOS5.5上安装Python2.7及ez_setup和pip包 下载 首先从Python官方下载源码包下载 编译安装 这里将python安装到/opt/python27目录下 tar xvf Python-2.7.10.tgz ./configure --prefix=/opt/python27 --enable-shared make sudo make install 安装完成后,为了避免有时候运行python报下面的错误 /opt/python27/bin/python: erro

CentOS6下编译安装Python2.7.6方法

关于在CentOS6下编译安装Python2.7.6的方法非常的多了,小编以前也介绍过相关的文章了,下面一聚教程小编再来为各位介绍一下吧,希望文章能帮助到各位. CentOS下面Python在升级到2.7.6的时候,没有找到安装包直接安装,只能通过源代码编译的方式来安装Python 2.7.6版本.这篇是编译和安装Python2.7.6的过程记录. CentOS系统中安装了development tools.要编译安装Python,执行下面代码:  代码如下 复制代码 $ pushd /usr/

CentOS6.5上配置Python2.7+OpenCV2.4.7

本文讲述在Linux上使用配置Python调用OpenCV的开发环境 环境:CentOS 6.5 +Python2.7.8+OpenCV2.4.7 0.安装OpenCV环境要求(Installation in Linux) OpenCV.org的要求: GCC 4.4.x or later() CMake 2.8.7 or higher Git(如果直接下载了源码,这个没必要) GTK+2.x or higher, including headers (libgtk2.0-dev) pkg-co

LAMP+Centos6.5上安装zabbix

系统版本:centos6.5 内核版本:2.6.32-358.el6.x86_64 yum安装LAMP环境: yum install -y gcc gcc-c++httpd httpd-devel mysql msql-server mysql-devel php php-mysql php-common php-gdphp-mbstring php-mcrtpt php-devel php-xml php-bcmath libcurl-develnet-snmp-devel 2.  添加用户及

在CentOS6.1上安装puppet最新版本puppet-3.6.2版本问题

前述: 最近发现了一个问题,在CentOS6.4上安装puppet,直接安装一个puppet官方源即可,然后直接使用yum安装puppet. 但是现在在CentOS6.1上安装puppet-3.6.2,发现很多puppet所需要的依赖包的版本太高,而CentOS6.1提供的软件版本太低,无法满足puppet的安装,在安装puppet时会提示很多依赖包,需要安装,而这个安装无法通过yum安装,需要自己下载rpm包安装,特别麻烦. 后来想过安装低版本的puppet,比如安装3.2.4的,但是也可以,

CentOS6.9上安装cobbler2.6实现自动化安装Linux系统

CentOS6.9上安装cobbler2.6实现自动化安装Linux系统 cobbler可以批量部署Linux系统,并实现无人值守安装. cobbler依赖的服务:dhcp,tftp,http,pxe,kickstart 服务对应的端口号为dhcp--67,68;tftp--69;http--80;cobbler--25151 1.环境准备:最小化安装centos6.9mini,配置固定IP和本地yum源,关闭防火墙和selinux iptables -F setenforce 0 chkcon

最小化安装的64位CentOS6.5上安装Oracle11g R2

安装环境: 操作系统:CentOS6.5 x86_64 安装步骤: 一.按照官方文档安装依赖包,主要包如下: binutils-2.20.51.0.2-5.11.el6 (x86_64) compat-libcap1-1.10-1 (x86_64) compat-libstdc++-33-3.2.3-69.el6 (x86_64) compat-libstdc++-33-3.2.3-69.el6.i686 gcc-4.4.4-13.el6 (x86_64) gcc-c++-4.4.4-13.el