2018-04-25 发布

Linux下安装python-2.7

1.1k 次阅读  ·  读完需要 25 分钟

1

安装依赖的库

yum -y install python-devel openssl openssl-devel gcc sqlite sqlite-devel mysql-devel libxml2-devel libxslt-devel

Python

=================================================

下载python 2.7.13

www.python.org

[root@server2 ~]# mkdir /software
[root@server2 ~]# cd /software/
[root@server2 software]# wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
[root@server2 software]# ll
总用量 36852
-rw-r--r-- 1 root root 17076672 12月 18 04:21 Python-2.7.13.tgz
-rw-r--r-- 1 root root 20656090 1月 17 16:07 Python-3.5.3.tgz

解压文件

[root@server2 software]# tar -zxf Python-2.7.13.tgz

进入目录

[root@server2 software]# cd Python-2.7.13

编译安装

[root@server2 Python-2.7.13]# ./configure --prefix=/usr/local/python2.7 --with-threads --enable-shared
[root@server2 Python-2.7.13]# make && make altinstall

备份旧python相关命令

===> 有些版本/usr/bin/目录下不存在pip 忽略下面第一行命令即可
[root@server2 Python-2.7.13]# mv /usr/bin/pip /usr/bin/pip_old
[root@server2 Python-2.7.13]# mv /usr/bin/easy_install /usr/bin/easy_install_old
[root@server2 Python-2.7.13]# mv /usr/bin/python /usr/bin/python_old

新版本python命令做软连接,快捷使用

[root@server2 Python-2.7.13]# ln -s /usr/local/python2.7/lib/libpython2.7.so /usr/lib
[root@server2 Python-2.7.13]# ln -s /usr/local/python2.7/lib/libpython2.7.so.1.0 /usr/lib
[root@server2 Python-2.7.13]# ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python
[root@server2 Python-2.7.13]# ln -s /usr/local/python2.7/lib/libpython2.7.so /usr/lib64
[root@server2 Python-2.7.13]# ln -s /usr/local/python2.7/lib/libpython2.7.so.1.0 /usr/lib64

测试python是否可以正常使用

[root@server2 ~]# python
Python 2.7.13 (default, Apr 11 2017, 11:14:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

安装pip

下载最新版的pip,然后安装

[root@server2 Python-2.7.13]# cd /software/
[root@server2 software]# wget https://bootstrap.pypa.io/get-pip.py
[root@server2 software]# python get-pip.py

查找pip的位置

[root@server2 software]# find / -name pip
/usr/local/python2.7/bin/pip

找到pip2.7的路径,为其创建软链作为系统默认的启动版本

[root@server2 software]# ln -s /usr/local/python2.7/bin/pip /usr/bin/pip

测试pip是否可用

[root@server2 software]# pip install Pillow
Collecting Pillow
Downloading Pillow-4.1.0-cp27-cp27m-manylinux1_x86_64.whl (5.7MB)
100% |████████████████████████████████| 5.7MB 129kB/s
Collecting olefile (from Pillow)
Downloading olefile-0.44.zip (74kB)
100% |████████████████████████████████| 81kB 541kB/s
Building wheels for collected packages: olefile
Running setup.py bdist_wheel for olefile ... done
Stored in directory: /root/.cache/pip/wheels/20/58/49/cc7bd00345397059149a10b0259ef38b867935ea2ecff99a9b
Successfully built olefile
Installing collected packages: olefile, Pillow
Successfully installed Pillow-4.1.0 olefile-0.44

安装easy_install

下载最新版的easy_install,然后安装

[root@server2 software]# wget https://bootstrap.pypa.io/ez_setup.py
[root@server2 software]# python ez_setup.py

找到easy_install的路径,为其创建软链作为系统默认的启动版本

[root@server2 software]# ln -s /usr/local/python2.7/bin/easy_install /usr/bin/easy_install

测试easy_install是否可用

[root@server2 software]# easy_install beautifulsoup4
Searching for beautifulsoup4
Reading https://pypi.python.org/simple/beautifulsoup4/
Downloading https://pypi.python.org/packages/9b/a5/c6fa2d08e6c671103f9508816588e0fb9cec40444e8e72993f3d4c325936/beautifulsoup4-4.5.3.tar.gz#md5=937e0df0d699a1237646f38fd567f0c6
Best match: beautifulsoup4 4.5.3
Processing beautifulsoup4-4.5.3.tar.gz
Writing /tmp/easy_install-OSpCW5/beautifulsoup4-4.5.3/setup.cfg
Running beautifulsoup4-4.5.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-OSpCW5/beautifulsoup4-4.5.3/egg-dist-tmp-m3PXo5
zip_safe flag not set; analyzing archive contents...
Moving beautifulsoup4-4.5.3-py2.7.egg to /usr/local/python2.7/lib/python2.7/site-packages
Adding beautifulsoup4 4.5.3 to easy-install.pth file Installed /usr/local/python2.7/lib/python2.7/site-packages/beautifulsoup4-4.5.3-py2.7.egg
Processing dependencies for beautifulsoup4
Finished processing dependencies for beautifulsoup4

yum 安装工具只支持系统自带的python版本, 修改配置文件使其可正常使用

查看原版本python

[root@server2 software]# ll /usr/bin/python*
lrwxrwxrwx 1 root root 34 4月 11 11:20 /usr/bin/python -> /usr/local/python2.7/bin/python2.7
lrwxrwxrwx 1 root root 6 2月 15 14:33 /usr/bin/python2 -> python
-rwxr-xr-x 2 root root 9032 8月 18 2016 /usr/bin/python2.6 ==> 这个就是系统自带的python
-rwxr-xr-x 1 root root 1418 8月 18 2016 /usr/bin/python2.6-config
lrwxrwxrwx 1 root root 16 4月 11 10:47 /usr/bin/python-config -> python2.6-config
-rwxr-xr-x 2 root root 9032 8月 18 2016 /usr/bin/python_old

修改配置文件 /usr/bin/yum

#!/usr/bin/python ===> 修改为 #!/usr/bin/python2.6

测试yum是否可用

[root@server2 software]# yum -y install python-devel
已加载插件:fastestmirror, security
设置安装进程
Loading mirror speeds from cached hostfile
* epel: mirrors.aliyun.com
包 python-devel-2.6.6-66.el6_8.x86_64 已安装并且是最新版本
无须任何处理

好了,大功告成。

优化:编写一键安装python2.7的脚本

由于Centos 6.x的系统默认都是python2.6 ,如果服务器需要用2.7环境的话每台都得手动操作升级,工作量比较大, 编写脚本提升效率。(Centos 7.x版本的默认的python都是2.7.5版本)

创建用于存放python脚本的目录

[root@server2 software]# mkdir /script/python/
[root@server2 software]# cd /script/python/

由于国外python网站下载python安装包缓慢,可以提前下载下来,和install_py27.sh放在一起,在脚本中直接解压本地文件进行安装,我已经上传到网盘
点击我下载

开始编写脚本 install_py27.sh

#!/bin/sh
# __author__ = 'junxi' # This script is used by fast installed python2.7 ......
# write by 2017/04/11 echo "##############start run install for python2.7 script############"
yum -y install python-devel openssl openssl-devel gcc sqlite sqlite-devel mysql-devel libxml2-devel libxslt-devel
mkdir /software
mv Python-2.7.13.tgz /software
cd /software
tar -zxf Python-2.7.13.tgz
cd Python-2.7.13/
./configure --prefix=/usr/local/python2.7 --with-threads --enable-shared
make
make altinstall
mv /usr/bin/pip /usr/bin/pip_old
mv /usr/bin/easy_install /usr/bin/easy_install_old
mv /usr/bin/python /usr/bin/python_old
ln -s /usr/local/python2.7/lib/libpython2.7.so /usr/lib
ln -s /usr/local/python2.7/lib/libpython2.7.so.1.0 /usr/lib
ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python
ln -s /usr/local/python2.7/lib/libpython2.7.so /usr/lib64
ln -s /usr/local/python2.7/lib/libpython2.7.so.1.0 /usr/lib64
cd /software
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
ln -s /usr/local/python2.7/bin/pip /usr/bin/pip
echo "############更换pip源为国内淘宝源##########"
mkdir /root/.pip/
touch /root/.pip/pip.conf
cat >> /root/.pip/pip.conf << EOF
[global]
index-url=http://mirrors.aliyun.com/pypi/simple/ [install]
trusted-host=mirrors.aliyun.com
EOF pip install Pillow
sed -i 's#\/usr/bin/python#\/usr/bin/python2.6#g' /usr/bin/yum
yum -y install python-devel
echo 'the install script is the end......'

把Python-2.7.13.tgz文件和install_py27.sh脚本下载下来,放在同一个目录下:
运行下面命令进行安装

/bin/sh install_py27.sh

安装完成后执行python查看版本

赞  |   1收藏  |  1
 

Linux下安装python-2.7 先zlib的更多相关文章

  1. Linux 下安装Python报错:zlib not available

    问题描述: 在Linux下安装Python时出现一个错误:zipimport.ZipImportError: can't decompress data; zlib not available 详细错 ...

  2. linux下安装python

    在Linux下安装Python的操作相当简单,按如下步骤操作即可: 命令: wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgzt ...

  3. Linux 下安装python软件包(pip、nose、virtualenv、distribute )

    新手刚开始学习Python,目前学习<笨方法学python>ing- 在学习习题46时需要安装几个软件包:pip.nose.virtualenv.distribute !在此记录Linux ...

  4. linux下安装python linux下一些常用的命令

    注意 ubuntukylin-14.04.2-desktop-amd64 自带python2.7.6 这个说的比较详细 http://wenku.baidu.com/link?url=gaeFcQrc ...

  5. python 基础1.1--windows/linux 下安装python

    一.windows下安装python 1>windows上python后缀是.msi的,下载下来后,直接双击运行.会在c盘生成python.exe的文件,把python.exe的文件加入到win ...

  6. Linux下安装python,mysql,redis

    linux 安装Python3 1.python下载 请在终端输入如下命令: cd /home wget http://cdn.npm.taobao.org/dist/python/3.6.5/Pyt ...

  7. linux下安装python环境

    1.linux下安装python3 a. 准备编译环境(环境如果不对的话,可能遇到各种问题,比如wget无法下载https链接的文件) yum groupinstall 'Development To ...

  8. 环境部署(九):linux下安装python+chrome+Xvfb

    在基于selenium进行的UI自动化测试中,开发调试环境一般都是windows操作系统.完成后需要部署到专门的测试环境. 如要要部署到linux环境的服务器(阿里云.腾讯云)执行,那么测试脚本也需要 ...

  9. linux下安装python,Django,虚拟环境

    linux下python安装步骤: 1.下载python3源码包 wget https://www.python.org/ftp/python/3.6.6/Python-3.6.7.tgz 2.下载p ...

  10. Linux下安装python虚拟环境(virtualenv,vritulaenvwrapper)

    一.virtualenv virtualenv是如何创建"独立"的Python运行环境的呢? 原理很简单,就是把系统Python复制一份到virtualenv的环境,用命令sour ...

随机推荐

  1. 为phpStorm 配置PHP_CodeSniffer自动检查代码

    通过composer 安装PHP_CodeSniffer : squizlabs/PHP_CodeSniffer gihub地址 composer global require "squiz ...

  2. Vue工作原理小结

    本文能帮你做什么?1.了解vue的双向数据绑定原理以及核心代码模块2.缓解好奇心的同时了解如何实现双向绑定为了便于说明原理与实现,本文相关代码主要摘自vue源码, 并进行了简化改造,相对较简陋,并未考 ...

  3. Scrum立会报告+燃尽图(十月十九日总第十次):

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2246 项目地址:https://git.coding.net/zhang ...

  4. 软工第十二周个人PSP

    11.30--12.6本周例行报告 1.PSP(personal software process )个人软件过程. C(类别) C(内容) ST(开始时间) ET(结束时间) INT(间隔时间) Δ ...

  5. Android源码项目目录结构

    src: 存放java代码 gen: 存放自动生成文件的. R.java 存放res文件夹下对应资源的id project.properties: 指定当前工程采用的开发工具包的版本 libs: 当前 ...

  6. Alpha 冲刺(9/10)

    队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭鸭鸭鸭鸭鸭鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作 多次测试软件运行 学习OPENMP ...

  7. 主从复制redis

    编辑主服务器的配置文件 注释下面一项 # slaveof  192.168.10.1  6379 主从复制 一主可以有多从,支持链式连级 一主多从 1:修改从服务器的配置文件/etc/redis.co ...

  8. Scrum冲刺博客汇总

    第一篇 Scrum冲刺博客 http://www.cnblogs.com/LZTZ/p/8886296.html 第二篇 Scrum冲刺博客 http://www.cnblogs.com/LZTZ/p ...

  9. PAT L1-017 到底有多二

    https://pintia.cn/problem-sets/994805046380707840/problems/994805121500692480 一个整数“犯二的程度”定义为该数字中包含2的 ...

  10. Android自动化 -- sendevent/getevent 用法

    getevent&sendevent 是android系统下的一个工具,可以 模拟 多种按键和触屏操作,产生的是raw event,raw event经过event hub处理产生最终的ges ...