安裝前基礎環境
安裝前准備
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\用戶名\pip\pip.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)