Ubuntu,Deepin安装virtualenv

安装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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值