mkvirtualenv与virtualenv

Posted Jason_WangYing

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mkvirtualenv与virtualenv相关的知识,希望对你有一定的参考价值。

好长时间没有创建新项目,虚拟环境还记得,但是今天在创建时我用了virtualenv来创建,创建后用workon发现没有东西,找了下文档,才发现用mkvirtualenv来创建才会在workon中有记录,并且创建成功后会自动进入虚拟环境。

jason-macbook-pro:django-wechat-example-master wangying$ mkvirtualenv testvir
created virtual environment CPython3.7.6.final.0-64 in 749ms
  creator CPython3Posix(dest=/Users/wangying/.virtualenvs/testvir, clear=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/wangying/Library/Application Support/virtualenv)
    added seed packages: pip==20.1.1, setuptools==49.1.0, wheel==0.34.2
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
virtualenvwrapper.user_scripts creating /Users/wangying/.virtualenvs/testvir/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/wangying/.virtualenvs/testvir/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/wangying/.virtualenvs/testvir/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/wangying/.virtualenvs/testvir/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/wangying/.virtualenvs/testvir/bin/get_env_details
(testvir) jason-macbook-pro:django-wechat-example-master wangying$ workon
backenev
firstEvn
testvir
workjob
(testvir) jason-macbook-pro:django-wechat-example-master wangying$ deactivate
jason-macbook-pro:django-wechat-example-master wangying$ rmvirtualenv testvir
Removing testvir...
jason-macbook-pro:django-wechat-example-master wangying$ 

这是直接用virtualenv来安装虚拟环境,没有加入管理,这种的话需要直接进入对应的文件,在文件的/bin/里面有activate文件,运行:source activate,进入对应的虚拟环境。

jason-macbook-pro:demo wangying$ virtualenv testWechat
created virtual environment CPython3.7.6.final.0-64 in 926ms
  creator CPython3Posix(dest=/Users/wangying/Downloads/django-wechat-example-master/demo/testWechat, clear=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/wangying/Library/Application Support/virtualenv)
    added seed packages: pip==20.1.1, setuptools==49.1.0, wheel==0.34.2
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
jason-macbook-pro:demo wangying$ workon testWechat
ERROR: Environment 'testWechat' does not exist. Create it with 'mkvirtualenv testWechat'.
jason-macbook-pro:demo wangying$ workon
backenev
firstEvn
workjob

最后附上虚拟环境操作的命令

安装虚拟环境的命令如下:
  sudo pip install virtualenv
  sudo pip install virtualenvwrapper

创建虚拟环境的命令如下:
  mkvirtualenv 虚拟环境名称
  例:
  mkvirtualenv hj_django

退出虚拟环境的命令如下:
  deactivate

查看与使用:
  workon 两次table

删除虚拟环境的命令如下:
  rmvirtualenv 虚拟环境名称
  例:
  先退出:deactivate
  再删除:rmvirtualenv py_django

包安装:
  pip install 包名(需要的环境包)

以上是关于mkvirtualenv与virtualenv的主要内容,如果未能解决你的问题,请参考以下文章

virtualenv虚拟环境常用操作命令 mkvirtualenv workon rmvirtualenv

python虚拟环境的搭建命令mkvirtualenv

mkvirtualenv创建python虚拟环境

mkvirtualenv command not found解决

virtualenv模块

virtualenv模块