CentOS安裝配置python3環(huán)境
1. 獲取源碼
國(guó)內(nèi)可以從華為鏡像源獲劝唐弧:https://mirrors.huaweicloud.com/python/,在頁面中進(jìn)入對(duì)應(yīng)的版本文件夾婿牍,獲取.tar.xz格式的源碼包,下以3.7.4為例
wget https://mirrors.huaweicloud.com/python/3.7.4/Python-3.7.4.tar.xz
tar Python-3.7.4.tar.xz
cd Python-3.7.4
2. 編譯
2.1 先看一下有沒有安裝openssl-devel包
rpm -aq|grep openssl
2.2 如果沒有,就安裝一下,不然pip3沒法裝東西
yum install openssl-devel -y
2.3 配置也颤、編譯、執(zhí)行
./configure --prefix=/usr/python37 --with-ssl
make&make install
2.4 報(bào)錯(cuò)與解決
- 報(bào)錯(cuò):
ModuleNotFoundError: No module named '_ctypes'
yum install libffi-devel -y
3. 配置
3.1 配置python3和pip3的軟鏈接
ln -s /usr/python37/bin/python3 /usr/bin/python3
ln -s /usr/python37/bin/pip3 /usr/bin/pip3
3.2 升級(jí)pip3到最新版本
pip3 install --upgrade pip
3.3 配置pip3鏡像源
配置文件路徑為~/.pip/pip.conf,如果沒有就創(chuàng)建一下
mkdir ~/.pip
touch ~/.pip/pip.conf
pip.conf的內(nèi)容更換為
[global]
timeout = 6000
index-url = http://mirrors.aliyun.com/pypi/simple/
trusted-host = pypi.tuna.tsinghua.edu.cn
3.4 配置pip3的安裝目錄到環(huán)境變量
打開~/.bashrc,在最后添加如下內(nèi)容:
export PATH=/usr/python37/bin:$PATH
然后執(zhí)行如下命令生效
source ~/.bashrc