首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python3 virtualenv virtualenvwrapper

python3 virtualenv virtualenvwrapper

作者头像
Devops海洋的渔夫
发布2019-05-31 10:58:22
8950
发布2019-05-31 10:58:22
举报
文章被收录于专栏:Devops专栏Devops专栏

pip3 安装 virtualenv

pip3 install virtualenv

pip3 安装 virtualenvwrapper

安装虚拟环境包装器的目的是使用更加简单的命令来管理虚拟环境。 pip3 install virtualenvwrapper

配置环境变量

修改用户home目录下的配置文件.bashrc,添加如下内容:

export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

使用source .bashrc命令使配置文件生效。

执行操作如下:

[root@centos6 ~]# ls /usr/local/bin/virtualenvwrapper.sh
/usr/local/bin/virtualenvwrapper.sh
[root@centos6 ~]# cd ~
[root@centos6 ~]# vim .bashrc
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
[root@centos6 ~]# source .bashrc
-bash: /root/pyenv/python27/bin/activate: No such file or directory
virtualenvwrapper.user_scripts creating /root/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postmkproject
virtualenvwrapper.user_scripts creating /root/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /root/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/get_env_details
[root@centos6 ~]# 
[root@centos6 ~]# ls -ll -a | grep vir
drwxr-xr-x   2 root root    4096 May 28 15:49 .virtualenvs
[root@centos6 ~]# 

创建python3虚拟环境

mkvirtualenv -p python3 虚拟环境名称

例: mkvirtualenv -p python3 py_django

操作如下:

# 创建一个放置虚拟环境的路径
[root@centos6 opt]# mkdir test_venv
[root@centos6 opt]# cd test_venv/
[root@centos6 test_venv]# ls
# 创建虚拟环境
[root@centos6 test_venv]# mkvirtualenv -p python3 py_django
Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/usr/local'
New python executable in /root/.virtualenvs/py_django/bin/python3
Not overwriting existing python script /root/.virtualenvs/py_django/bin/python (you must use /root/.virtualenvs/py_django/bin/python3)
Installing setuptools, pip, wheel...
done.
(py_django) [root@centos6 test_venv]# ls
(py_django) [root@centos6 test_venv]# 

退出虚拟环境

deactivate

(py_django) [root@centos6 test_venv]# de
deactivate  deallocvt   debugfs     declare     delpart     depmod      
(py_django) [root@centos6 test_venv]# deactivate 
[root@centos6 test_venv]# ls
[root@centos6 test_venv]# 

查看所有虚拟环境

查看所有虚拟环境的命令如下:

提示:workon后面有个空格,再按两次tab键。

workon 两次tab键

[root@centos6 test_venv]# workon py_django
py_django
[root@centos6 test_venv]# 

重新进入虚拟环境工作

[root@centos6 test_venv]# workon py_django
(py_django) [root@centos6 test_venv]# 
(py_django) [root@centos6 test_venv]# 

删除虚拟环境

删除虚拟环境的命令如下:

rmvirtualenv 虚拟环境名称

例: 先退出:deactivate 再删除:rmvirtualenv py_django

(py_django) [root@centos6 test_venv]# 
(py_django) [root@centos6 test_venv]# deactivate 
[root@centos6 test_venv]# 
[root@centos6 test_venv]# rmvirtualenv py_django
Removing py_django...
[root@centos6 test_venv]# 
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.05.28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • pip3 安装 virtualenv
  • pip3 安装 virtualenvwrapper
  • 配置环境变量
  • 创建python3虚拟环境
  • 退出虚拟环境
  • 查看所有虚拟环境
  • 重新进入虚拟环境工作
  • 删除虚拟环境
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档