Centos安装python3,pip3

1.环境准备

安装前需要yum需要的包

yum install gcc-c++
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

2.安装python3和pip3

2.1安装python

sudo  mkdir -p /usr/local/python3
cd /home/app   (安装包所在位置)
sudo tar -zxvf Python-3.6.5.tgz -C /usr/local/python3/ 
cd /usr/local/python3/
cd Python-3.6.5/

sudo ./configure --prefix=/usr/local/python3
sudo make 
sudo make install
sudo ln -s /usr/local/python3/bin/python3.6 /usr/local/bin/python3

出现Successfully installed pip-9.0.1 setuptools-28.8.0 则表示安装成功

如果未出现以上字样,或者出现卡顿情况,可以中断,重新执行make & make install

出现问题:zipimport.ZipImportError: can't decompress data; zlib not available,安装环境后从新编译安装

yum install zlib* -y

2.2安装pip

环境

sudo yum -y install epel-release # 首先安装 epel 扩展源
sudo yum -y install python-pip # 安装 python-pip
sudo yum clean all # 清除 cache

安装

cd /usr/local/python3     
wget --no-check-certificate https://github.com/pypa/pip/archive/9.0.1.tar.gz
tar -zvxf 9.0.1.tar.gz  # 解压文件
cd pip-9.0.1
python3 setup.py install # 使用 Python 3 安装
sudo ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3

查看版本号:

python3 -V

3.配置环境变量

sudo vi ~/.bash_profile

写入:

#配置python
export PYTHON_HOME=/usr/local/bin/python3
export PATH=$PYTHON_HOME/bin:$PATH

按ESC 然后输入 :wq 保存

使配置生效:

source ~/.bash_profile

查看是否生效:

echo $PYTHON_HOME

4.升级pip

pip3 install --upgrade pip #升级 pip

出现问题:pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

需要对Python重新编译

./configure --with-ssl
make & make install

参考

linux安装python3,pip3,并加载启动服务

Linux系统安装Python3环境

你可能感兴趣的:(#,环境和配置,linux,Python3)