参考文章:
https://blog.csdn.net/lianxiaopang/article/details/78492829
https://www.cnblogs.com/xiaoerjun/p/9837029.html
https://blog.csdn.net/weixin_43868754/article/details/104800827
一. 下载与安装 python3.6.8
- 下载
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
- 关联库安装
yum -y groupinstall "Development tools"
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
- 解压,编译,安装
tar -zxvf Python-3.6.8.tgz # 解压
cd Python-3.6.8 # 进入解压后的目录
# 编译,安装
./configure --prefix=/usr/local/python3
make
make install
安装成功会有如下输出:
- 创建python3和pip3的软连接(易错!!!)
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
二. 创建python3的虚拟环境
- 安装virtualenv、virtualenvwrapper(建议使用豆瓣源加速安装!!!)
pip3 install --upgrade pip
pip3 install -i https://pypi.douban.com/simple virtualenv
pip3 install -i https://pypi.douban.com/simple virtualenvwrapper
- 进入~/.bashrc文件中,定义virtualenvwrapper路径(易错!!!)
vim ~/.bashrc
VIRTUALENVWRAPPER_PYTHON=/usr/local/python3/bin/python3 # 指定virtualenvwrapper执行的python版本
export WORKON_HOME=$HOME/.virtualenvs # 指定虚拟环境存放目录,.virtualenvs目录名可自拟
source /usr/local/bin/virtualenvwrapper.sh # virtualenvwrapper.sh所在目录
- 运行.bashrc文件
source ~/.bashrc
- 创建虚拟环境
mkvirtualenv python3
- 启动虚拟环境
workon python3
三. 工程根目录配置与模块导入
详情请见:Linux中Python模块导入
来源:CSDN
作者:岚清子
链接:https://blog.csdn.net/weixin_43868754/article/details/104603261