一.安装python,pip
1.安装指定版本的python3.8
sudo apt install python3.8

2.发现本地已经有python3.6,如何将python3.8作为默认的python(注意对于一个完整的linux系统,事先都会安装一个python,修改默认python要慎重,因为修改之后,系统可能不支持新的默认python)
which python
#或者
which python
#查看可执行文件存放目录
 使用软链接 ln -s 目标路径 软链接路径 例如: ln -s /usr/bin/python /usr/bin/python3.8 就可以在终端,任意路径下,输入python就可以运行python3.8了
3.安装pip命令行工具
sudo apt install python3-pip

4.修改pip工具默认指向的python版本
which pip3
vim /usr/bin/pip3

/usr/bin/pip3 中#!/usr/bin/python3运行后,指的是什么版本的python,pip命令行工具就被用在了哪个版本的python下
二.安装virtualenv虚拟环境
1.安装虚拟环境
sudo pip3 install virtualenv

2.安装虚拟环境扩展包
sudo pip3 install virtualenvwrapper

3.用户/home目录下配置文件.bashrc(可能会没有,这个文件vim .bashrc就可以了)
vim .bashrc
输入以下内容
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 # python路径,可以不写
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/python3/bin/virtualenv # virtualenv虚拟环境路径,可不写
source /usr/local/bin/virtualenvwrapper.sh
需要注意的是如果,不写python路径,可能会报错: 查找原因
vim /usr/local/bin/virtualenvwrapper.sh
 我们可以看到,如果不在.bashrc中设置python路径,virtualenv就会自动使用命令 which python,找到python可执行命令的路径,如果which python结果为空,就会报错
source .bashrc # 使配置文件生效

4.创建,登录,退出虚拟环境
mkvirtualenv -p python3 虚拟环境名称

登录
workon py_tornado
退出
deactivate
|