Centos安装python3-2

前言:

python3应该是python的趋势所在,当然目前争议也比较大,这篇随笔的主要目的是记录在linux64下搭建python3环境的过程

以及碰到的问题和解决过程。

  另外,如果本机安装了python2,尽量不要管他,使用python3运行python脚本就好,因为可能有程序依赖目前的python2环境,

比如yum!!!!!

不要动现有的python2环境!

不要动现有的python2环境!

不要动现有的python2环境!

重要的使用说三遍!

一、安装python3.6

下载python3.6安装包:

wget --no-check-certificate https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz

解压到当前目录:

tar -zxvf Python-3.6.0.tgz

cd Python-3.6.0
其中一条
./configure --prefix=/usr/local/python3.5 --enable-shared
./configure --prefix=/usr/local/python3.5 --enable-optimizations(系统推荐)


make & make install
# 不要复制,用手去敲
ln -s /usr/local/python3.5/bin/python3 /usr/bin/python3

此时运行python3命令的话会报错,缺少.so文件,我们需要进行如下操作:

cp -R /usr/local/python3.5/lib/* /usr/lib64/

ok!此时python3的基础环境已经安装完成!

二、安装pip以及setuptools

1、安装pip前需要前置安装setuptools(基础包)

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

tar -zxvf setuptools-19.6.tar.gz

cd setuptools-19.6

python3 setup.py build

python3 setup.py install

报错:RuntimeError: Compression requires the (missing) zlib module

我们需要在linux中安装zlib-devel包,进行支持。

yum install zlib-devel

需要对python3.6进行重新编译安装。

cd python3.6

make & make install

又是漫长的编译安装过程。

重新安装setuptools

python3 setup.py build

python3 setup.py install

2、安装pip(管理包)

wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb

tar -zxvf pip-8.0.2.tar.gz

cd pip-8.0.2

python3 setup.py build

python3 setup.py install

如果没有意外的话,pip安装完成。

3.安装virtualenv(虚拟环境)

pip install virtualenv

报错:pip is configured with locations that require TLS/SSL, however the ssl module in python is not available.
Collecting xxx
Could not fetch URL https://pypi.python.org/simple/xxxx/: There was a problem confirming the ssl certificate: Can’t connect to HTTPS URL because the SSL module is not available. - skipping
Could not find a version that satisfies the requirement xxx (from versions: )
No matching distribution found for xxx


3.1.查看openssl安装包,发现缺少openssl-devel包
[root@Leen ~]# rpm -aq|grep openssl
openssl-0.9.8e-20.el5
openssl-0.9.8e-20.el5

3.2.yum安装openssl-devel
[root@Leen ~]# yum install openssl-devel -y

继续重新编译安装python3.6

ok,完成安装


python 报错:Python3.6安装报错 configure: error: no acceptable C compiler found in $PATH

安装python的时候出现如下的错误:

[root@master ~]#./configure --prefix=/usr/local/python3.6?

checking build system type... i686-pc-linux-gnu

checking host system type... i686-pc-linux-gnu
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... linux
checking for --without-gcc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/pythonSoft/Python-3.3.4':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

由于本机缺少gcc编译环境

1、通过yum安装gcc编译环境:yum?install -y?gcc

2、本机没有安装yum功能,可下载gcc安装包:https://gcc.gnu.org/

原文地址:https://www.cnblogs.com/Xingtxx/p/11271554.html