安装pip
我用的Deepin系统,默认已经安装了 python2 和 python3,查看版本
默认Ubuntu还是Deepin都没有安装pip,我们这里安装pip3
(因为Deepin为国产操作系统,所以速度还算正常,Ubuntu可以自己更换源)
Ubuntu 的软件源配置文件是 /etc/apt/sources.list
。将系统自带的该文件做个备份,将该文件替换为下面内容,即可使用 TUNA 的软件源镜像。
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
安装virtualenvwrapper
默认使用python官方的源,加入 -i参数可以指定下载源,我这里使用的豆瓣
pip3 install virtualenvwrapper -i https://pypi.douban.com/simple
全局修改pip源
- 首先在家目录上查看是否有.pip文件
- 有则进入pip文件,找到pip.conf
- 没有则创建指定文件(为了区分我这里使用了清华源)
mkdir ~/.pip
touch ~/.pip/pip.conf
vim ~/.pip/pip.conf
配置文件
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
timeout = 6000
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
virtualenv软链接
# 刚开始因为Python版本的原因会找不到 virtualenv
virtualenv
# 其实已经安装好了,只需要找到它,设置软链接即可
sudo find / -name virtualenv
sudo ln -s /home/zzxx/.local/bin/virtualenv /usr/bin/virtualenv
# 再次输入 virtualenv 已经可以执行命令
编辑 .bashrc
查看virtualenvwrapper.sh位置
# 指定虚拟环境存放地址
export WORKON_HOME=$HOME/.virtualenvs
# 这个文件在不同的 linux 版本中位置不同 需要 sudo find / -name virtualenvwrapper.sh
source /usr/local/bin/virtualenvwrapper.sh
下面配置文件写入 ~/.bashrc
export WORKON_HOME=$HOME/.virtualenvs
source /home/zzxx/.local/bin/virtualenvwrapper.sh
默认virtualenv使用的是python2,这里需要指定为python3
最终.bashrc文件
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
source /home/zzxx/.local/bin/virtualenvwrapper.sh
刷新配置
- source !$ (!$ 显示系统最近的一条参数 之前我 vim ~/.basrhc 最后一条参数 ~/.bashrc )
测试虚拟环境
- 新建虚拟环境test: mkvirtualenv test
- 退出虚拟环境: deactivate
- 查看虚拟环境列表: workon
- 进入虚拟环境: workon test
虚拟环境安装tornado
在虚拟环境中无需输入pip3 python3 直接使用 pip python 系统已经给重命名了,将python版本隔离
pip install tornado
退出虚拟环境,进入主环境后没有tornado(实现了环境隔离)
pip3 list | grep tornado