CentOS下安裝python3環境及pypy環境


安裝前基礎環境

1. win7虛擬機CentOS7.6系統

2. 網絡環境通過NAT方式

3. 已經配置到yum倉庫並系統自帶有python2.7

安裝前准備

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

解壓源碼包並進入

tar xf Python-3.6.5

cd Python-3.6.5

配置安裝參數

./configure --prefix=/usr/local/python3 enable-optimizations --with-ssl

編譯並安裝

make &&make install

 

安裝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

下載解壓運行即可

tar xf PyPy3.6

 

方式三:通過官方的二進制文件安裝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

 

配置環境變量

vim ~/.bashrc

export PATH=$PATH:/usr/local/python3/bin

export PATH=$PATH:/root/pypy3.6-v7.1.1-linux64/bin

 

 

因為yum是依賴python的,所以這里我們修改了默認的python,就要要修改yum,讓其運行指向舊的版本

vim /usr/bin/yum

修改#!/usr/bin/python #!/usr/bin/python2

vim /usr/libexec/urlgrabber-ext-down

vim /usr/bin/yum-config-manager

同上

 

安裝virtualenv工具

pip3 install virtualenv

指定pypy作為解釋器創建虛擬環境

virtualenv -p /root/pypy3.6-v7.1.1-linux64/bin/pypy3 mypypy3

激活虛擬環境

source mypypy3/bin/activate

 

 

獲取並安裝pip

wget https://bootstrap.pypa.io/get-pip.py

pypy 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/

方法1pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ flask  --trusted-host  pypi.tuna.tsinghua.edu.cn

方法2

linux》中在~/.pip/pip.conf文件中添加如下內容(若未創建則創建文件和文件夾)

[global]

index-url = https://pypi.tuna.tsinghua.edu.cn/simple

[install]

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

解決:yum install -y gcc

2. zipimport.ZipImportError: can’t decompress data

解決:安裝zlib zlib-devel

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)

  RuntimeWarning)

解決:同上,安裝yum install libssh,創建libcrypto.so.1.0.0軟鏈接指向/usr/lib64/下的libcrypto.so.1.0.0文件

5. ./bin/pip3 -V

/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)

  RuntimeWarning)

解決:同上

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM