CentOS6.7升级Python3.4.3

xiaoxiao2021-02-28  115

##安装所需依赖包 yum groupinstall "Development Tools" -y yum groupinstall "Development Libraries" -y yum install gcc* cmake make gd libjpeg libjpeg-devel libpng libpng-devel freetype-devel yum-fastestmirror -y yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel -y

yum install zlib zlib-devel yum install bzip2 bzip2-devel

yum install openssl-devel -y

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. 的解决

用pip安装依赖包时默认访问https://pypi.Python.org/simple/,但是经常出现不稳定以及访问速度非常慢的情况,国内厂商提供的pipy镜像目前可用的有:

http://pypi.douban.com/ 豆瓣http://pypi.mirrors.ustc.edu.cn/simple/ 中国科学技术大学

有两种方式使用我们自己指定的镜像源,第一种是手动指定:

pip -i http://pypi.douban.com/simple install Flask -- trusted-host pypi.douban.com

不过这种方式在每次安装时都要手动指定,因此你可以把它写在配置文件中,这就是第二种方法,在当前用户目录下创建.pip文件夹

mkdir ~/.pip

然后在该目录下创建pip.conf文件填写:

[global] trusted-host=mirrors.aliyun.com index-url=http://mirrors.aliyun.com/pypi/simple/

上面配置是针对OSX/Linux系统,如果是Windows,那么创建%HOMEPATH%\pip\pip.ini文件来配置。

例如:C:\Users\fxl\pip\pip.ini

pip.ini配置的主要一些配置: [global] trusted-host=mirrors.aliyun.com index-url=http://mirrors.aliyun.com/pypi/simple/

这样就会用ssl模块了

进入python安装包,找到Setup文件,用 vi 打开 cd Python-2.7.11/Modules vi Setup.dist 找到 # Socket module helper for SSL support; you must comment out the other # socket line above, and possibly edit the SSL variable: #SSL=/usr/local/ssl#_ssl _ssl.c \ #       -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ #       -L$(SSL)/lib -lssl -lcrypto 把前面的 # 号去掉,修改为 # Socket module helper for SSL support; you must comment out the other # socket line above, and possibly edit the SSL variable: SSL=/usr/local/ssl _ssl _ssl.c \        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \       -L$(SSL)/lib -lssl -lcrypto 保存退出,重新编译安装(注意: 安装python之前,最好确认一下gcc是否安装。apt-get install -y gcc

____________________________________

[root@xu  ~]# python -V

Python 2.6.6

[root@xu  ~]# 

2、下载Python3.4.3

下载并上传到tmp目录

[root@xu  tmp]# ls

Python-3.4.3.tgz  yum.log

[root@xu  tmp]# 

3、创建Python安装目录

[root@xu  tmp]# mkdir /opt/python3.4

4、解压tar文件

[root@xu tmp]# tar -zxvf Python-3.4.3.tgz 

[root@xu tmp]# cd Python-3.4.3

[root@xu Python-3.4.3]# pwd

/tmp/Python-3.4.3

5、配置及安装

[root@xu Python-3.4.3]# ./configure --prefix=/usr/local/python

[root@xu Python-3.4.3]# make

[root@xu Python-3.4.3]# make install

6、建立软连接,使系统默认python指向新安装的python

[root@xu tmp]# mv /usr/bin/python /usr/bin/python2.6.6

[root@xu tmp]# ln -s /usr/local/python /usr/bin/python

[root@xu tmp]# python -V

Python 3.4.3

不错,到此升级成功,然后编辑yum默认的python为旧版本python

[root@xu tmp]# vim /usr/bin/yum 

修改第一行,如下

修改前:#!/usr/bin/python

修改后:#!/usr/bin/python2.6.6

保存退出:(vim命令):wq

注意:现在还没有安装easy_install和pip,且安装好后需要配置环境变量

yum install zlib-devel

wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-12.0.3.tar.gz#md5=f07e4b0f4c1c9368fcd980d888b29a65

2. 安装  tar -zxvf setuptools-12.0.3.tar.gz cd setuptools=12.0.3 python setup.py install 3. 出现错误提示: Installed /usr/local/python2.7.3/lib/python2.7/site-packages/supervisor-4.0.0_dev-py2.7.egg Processing dependencies for supervisor==4.0.0-dev Searching for meld3>=1.0.0 Reading https://pypi.python.org/simple/meld3/ Download error on https://pypi.python.org/simple/meld3/: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed -- Some packages may not be found! Couldn't find index page for 'meld3' (maybe misspelled?) Scanning index of all packages (this may take a while) Reading https://pypi.python.org/simple/ Download error on https://pypi.python.org/simple/: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed -- Some packages may not be found! No local packages or download links found for meld3>=1.0.0 error: Could not find suitable distribution for Requirement.parse('meld3>=1.0.0') 解决办法: 上网查询了问题原因: 是curl的证书太老了需要下载最新的证书: 下载最新的证书文件 、   $ wget http://curl.haxx.se/ca/cacert.pem   更名为ca-bundle.crt放置到默认目录   $ mv cacert.pem ca-bundle.crt  $ mv ca-bundle.crt /etc/pki/tls/certs

安装pip

[root@xu tmp]# easy_install pip

-bash: easy_install: command not found

配置python环境变量

[root@xu tmp]# vim /etc/profile

在最后面加上

PYTHON_HOME=/opt/python3.4

export PATH=$PYTHON_HOME/bin:$PATH

保存退出

[root@xu tmp]# source /etc/profile

执行上面命令,是环境变量立即生效

安装pip

[root@xu tmp]# easy_install pip

Searching for pip

Best match: pip 6.0.8

Adding pip 6.0.8 to easy-install.pth file

Installing pip script to /opt/python3.4/bin

Installing pip3.4 script to /opt/python3.4/bin

Installing pip3 script to /opt/python3.4/bin

Using /opt/python3.4/lib/python3.4/site-packages

Processing dependencies for pip

Finished processing dependencies for pip

到此ok,python升级完成,easy_install和pip命令可以正常使用

升级pip

pip3 install --upgrade pip

转载请注明原文地址: https://www.6miu.com/read-38373.html

最新回复(0)