如何从Windows 10命令提示符激活虚拟环境?

时间:2017-10-23 18:26:24

标签: virtualenv virtualenvwrapper virtual-environment

我尝试使用Windows 10命令提示符创建并激活虚拟环境。我知道virtualenv正确安装,作为命令

venv activate

作品。我已经导航到我的virtualenv下载,下载\ venv \ Scripts,我正在尝试激活我的虚拟环境venv。我试过了

virtualenv venv activate

由于Windows没有将venv识别为命令,因此无法正常工作。我也试过了

String query = String.format("SELECT * FROM parent WHERE name='%s'", nname);

由于virtualenv说" venv激活"这也是行不通的。不是一个有效的论据。

9 个答案:

答案 0 :(得分:10)

使用虚拟环境的Scripts目录中的activate脚本:

> venv\Scripts\activate

这将激活您的虚拟环境,并且终端将根据您所在的目录如下所示:

(venv) C:\Users\acer\Desktop>

我希望这会有所帮助!

答案 1 :(得分:3)

如果你正在使用virtualenvwrapper-win,并使用DOS命令提示符(而不是像Powershell),则使用以下命令创建新的virtualenv:

mkvirtualenv myenv

并使用

激活
workon myenv

您应该定义环境变量WORKON_HOME以指向您希望virtualenvs驻留的位置。

如果您已安装virtualenvwrapper-win>=1.2.4,则virtualenvwrapper命令会为您提供可用列表命令:

go|c:\srv> virtualenvwrapper

 virtualenvwrapper is a set of extensions to Ian Bicking's virtualenv
 tool.  The extensions include wrappers for creating and deleting
 virtual environments and otherwise managing your development workflow,
 making it easier to work on more than one project at a time without
 introducing conflicts in their dependencies.

 virtualenvwrapper-win is a port of Dough Hellman's virtualenvwrapper to Windows
 batch scripts.

 Commands available:

   add2virtualenv: add directory to the import path

   cdproject: change directory to the active project

   cdsitepackages: change to the site-packages directory

   cdvirtualenv: change to the $VIRTUAL_ENV directory

   lssitepackages: list contents of the site-packages directory

   lsvirtualenv: list virtualenvs

   mkproject: create a new project directory and its associated virtualenv

   mkvirtualenv: Create a new virtualenv in $WORKON_HOME

   rmvirtualenv: Remove a virtualenv

   setprojectdir: associate a project directory with a virtualenv
   toggleglobalsitepackages: turn access to global site-packages on/off

   virtualenvwrapper: show this help message

   whereis: return full path to executable on path.

   workon: list or change working virtualenvs

答案 2 :(得分:0)

确保Python脚本文件夹位于您的环境变量中。

通常的路径是:(根据您的python版本,将“ admin”更改为Windows用户名和Python37-32路径)

“ C:\ Users \ admin \ AppData \ Local \ Programs \ Python \ Python37-32 \ Scripts”

答案 3 :(得分:0)

使用“ virtualenv”创建环境时,会将“ activate.bat”文件保存在脚本文件夹中,该文件夹源自您运行第一个命令的目录。例如,如果您从virtualenv env运行了命令C:/Users/Name/Documents/...,则.bat将位于C:/Users/Name/Documents/.../env/scripts/activate.bat中。您可以从那里运行它。

答案 4 :(得分:0)

只需使用以下命令即可激活您的virtualenv:workon myenvname

答案 5 :(得分:0)

您还可以像这样创建命令行脚本-

servicesProvider

将其保存在扩展名为“ .cmd”的记事本文件中。 你准备好了

答案 6 :(得分:0)

如果您安装了 anaconda,请打开 anaconda 终端并输入

> conda env list              # for list of environment you already have
> conda activate {env_name}   # to activate the environment

答案 7 :(得分:0)

这在 Anaconda 提示符下对我有用,

.\\myvenv\\Scripts\\activate.bat

答案 8 :(得分:-1)

  1. 启动python 3.7
  2. python -m virtualenv
    "You must provide a DEST_DIR"
  3. python -m venv demodjango("demodjango is file name)"
  4. activate.bat
  5. pip install django
  6. django-admin.py startproject demo1(demo1是我的项目)
  7. python manage.py runserver
    Performing system checks...
  8. 在命令提示符下执行此操作后,您将获得一个URL。单击该按钮,您将在浏览器窗口中看到一条消息,提示已正确安装Django。