安装前基础环境
安装前准备
1. python3.6.5源码包:https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz(可以在window下载,也可以在linux通过wget下载)
2. pypy3二进制包:https://bitbucket.org/pypy/pypy/downloads/pypy3.6-v7.1.1-linux64.tar.bz2
开始安装
源码包安装python3.6.5
安装所需依赖包
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 gcc
解压源码包并进入
配置安装参数
./configure --prefix=/usr/local/python3 enable-optimizations --with-ssl
编译并安装
安装pypy
方式一:通过yum安装pypy
rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
yum -y install pypy-libs pypy pypy-devel
pypy rpm下载地址:http://pkgs.org/search/?keyword=pypy
方式二:通过可移植二进制文件安装pypy
文件地址:https://github.com/squeaky-pl/portable-pypy
方式三:通过官方的二进制文件安装pypy
文件地址:https://bitbucket.org/pypy/pypy/downloads/pypy3.6-v7.1.1-linux64.tar.bz2
基本配置
添加软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
配置环境变量
export PATH=$PATH:/usr/local/python3/bin
export PATH=$PATH:/root/pypy3.6-v7.1.1-linux64/bin
因为yum是依赖python的,所以这里我们修改了默认的python,就要要修改yum,让其运行指向旧的版本
修改#!/usr/bin/python 为 #!/usr/bin/python2
vim /usr/libexec/urlgrabber-ext-down
vim /usr/bin/yum-config-manager
安装virtualenv工具
virtualenv -p /root/pypy3.6-v7.1.1-linux64/bin/pypy3 mypypy3
获取并安装pip
wget https://bootstrap.pypa.io/get-pip.py
更换pip镜像源
(1)阿里云 http://mirrors.aliyun.com/pypi/simple/
(2)豆瓣http://pypi.douban.com/simple/
(3)清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
(4)中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
(5)华中科技大学http://pypi.hustunique.com/
方法1:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ flask --trusted-host pypi.tuna.tsinghua.edu.cn
《linux》中在~/.pip/pip.conf文件中添加如下内容(若未创建则创建文件和文件夹)
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = https://pypi.tuna.tsinghua.edu.cn
《window》中在c:\user用户名pippip.ini中添加同上内容
python安装常见问题
1. configure: error: no acceptable C compiler found in $PATH
2. zipimport.ZipImportError: can’t decompress data
3. Running virtualenv with interpreter /root/pypy3.6-v7.1.1-linux64/bin/pypy3
/root/pypy3.6-v7.1.1-linux64/bin/pypy3: error while loading shared libraries: libbz2.so.1.0: cannot open shared object file: No such file or directory
解决:安装yum install bzip2-libs,如果已经存在,搜索find / -name libbz2.so的位置,创建一个软链接连接libbz2.so.1.0.6
ln -s /usr/lib64/libbz2.so.1.0.6 /usr/lib64/libbz2.so.1.0
4. /root/pypy3.6-v7.1.1-linux64/lib-python/3/hashlib.py:172: RuntimeWarning: The _hashlib module is not available, falling back to a much slower implementation (libcrypto.so.1.0.0: cannot open shared object file: No such file or directory)
解决:同上,安装yum install libssh,创建libcrypto.so.1.0.0软链接指向/usr/lib64/下的libcrypto.so.1.0.0文件
/root/pypy3.6-v7.1.1-linux64/lib-python/3/hashlib.py:172: RuntimeWarning: The _hashlib module is not available, falling back to a much slower implementation (libssl.so.1.0.0: cannot open shared object file: No such file or directory)