Python3.6环境安装
安装依赖环境
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
下载Python3
https://www.python.org/downloads
或
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
安装Python3
这里说下自定义目录安装
创建安装目录:
mkdir -p /usr/local/python3
解压:
tar -xzvf Python-3.6.0.tgz
进入解压后的目录:编译/安装
cd Python-3.6.0/
编译/安装:
./configure --prefix=/usr/local/python3
make
make install
建立python3的软链
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
配置环境变量
执行 vi ~/.bash_profile,打开配置文件,添加如下配置:
#配置python
export PYTHON_HOME=/usr/local/python3
export PATH=$PYTHON_HOME/bin:$PATH
保存退出(:wq),执行source ~/.bash_profile命令使配置生效
配置安装源
mkdir ~/.pip
vim ~/.pip/pip.conf
增加以下内容并保存即可,想更换只需更改index-url即可
[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
trusted-host = pypi.tuna.tsinghua.edu.cn
注:国内源列表
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣 http://pypi.douban.com/simple
Python官方 https://pypi.python.org/simple/
v2ex http://pypi.v2ex.com/simple/
中国科学院 http://pypi.mirrors.opencas.cn/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
问题
pip3.6安装包时报错
问题如下:
Can’t connect to HTTPS URL because the SSL module is not available
解决方案:
进入Python3.6解压包
cd Python-3.6.0/
编辑Modules/Setup文件解除SLL的注释
vi Modules/Setup
找到SLL位置处解除注释
209 #SSL=/usr/local/ssl
210 _ssl _ssl.c \
211 -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
212 -L$(SSL)/lib -lssl -lcrypto
重新编译安装
make clean
make
make install
make出错,fatal error: openssl/opensslv.h
问题如下:
fatal error: openssl/opensslv.h: No such file or directory
解决方案
没有安装openssl-devel引起,yum install openssl-devel即可