由于工作环境无法使用root账号,所有命令都加了sudo,root账号不需要sudo
- 安装依赖
sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
sudo yum install libffi-devel -y
- 选择一个目录,下载源码,具体下载地址,可以通过打开python的官方网站 -->Downloads-->Source code-->Latest Python 3 Release - Python 3.7.4-->拉到最下面,选择Gzipped source tarball-->右键复制链接获得
cd /opt
sudo wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
- 解压,配置,安装
tar -zxvf Python-3.7.4.tgz
cd Python-3.7.4
sudo ./configure --prefix=/usr/local/python3.7
sudo make && sudo make install
- 创建软链
sudo ln -s /usr/local/python3.7/bin/python3 /usr/bin/python3.7
sudo ln -s /usr/local/python3.7/bin/pip3 /usr/bin/pip3.7
- 安装virtualenv及其他基础库
sudo pip3.7 install --default-timeout=100 virtualenv
sudo pip3.7 install --default-timeout=100 requests
sudo pip3.7 install --default-timeout=100 pandas
- 创建virtualenv独立环境(独立第三方包的环境),python一定要绝对路径,不然会失效!
cd ~/
/usr/local/python3.7/bin/virtualenv -p /usr/bin/python3.7 venv3.7
chmod -R 777 ~/venv3.7/bin
- 激活与取消环境
source ~/venv3.7/bin/activate
deactivate
- 进入虚拟环境后安装第三方包
python -m pip install --user
参考
https://blog.csdn.net/Fichz/article/details/81162977
https://blog.csdn.net/qq_36288025/article/details/82534508
https://cloud.tencent.com/developer/ask/170212
https://www.cnblogs.com/zhaoyunlong/p/9651525.html