如何在 Windows 上激活 virtualenv?

问题描述 投票:0回答:3

我先删除了virtualenv,然后重新创建它。按照

post
中的说明运行.\\Envs\automation_cookbook\Scripts\activate.bat。但是提示根本没有改变。我怀疑我是否成功运行它。

PS C:\Users\yashi> rmvirtualenv automation_cookbook

    Deleted C:\Users\yashi\Envs\automation_cookbook

PS C:\Users\yashi> mkvirtualenv automation_cookbook
created virtual environment CPython3.9.0.final.0-64 in 329ms
  creator CPython3Windows(dest=C:\Users\yashi\Envs\automation_cookbook, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\yashi\AppData\Local\pypa\virtualenv)
    added seed packages: pip==20.3.1, setuptools==51.0.0, wheel==0.36.1
  activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
PS C:\Users\yashi> .\\Envs\automation_cookbook\Scripts\activate.bat
PS C:\Users\yashi> 
PS C:\Users\yashi> lsvirtualenv

dir /b /ad "C:\Users\yashi\Envs"
==============================================================================
automation_cookbook

编辑:我正在通过 virtualenvwrappe 尝试它

python virtualenv virtualenvwrapper
3个回答
5
投票

制作虚拟环境:

python -m venv <env-name>

激活:

Scripts/activate.bat

停用:

Scripts/deactivate.bat

删除:只需删除文件夹


0
投票

如果您使用

python -m venv <env-name>
创建了一个虚拟环境并且您正在使用 PowerShell

然后从同一个文件夹中,

./<env-name>/Scripts/activate.bat
将激活它

./<env-name>/Scripts/deactivate.bat
将停用它。

也会有

./<env-name>/Scripts/Activate.ps1
,但是没有匹配的
Deactivate.ps1


0
投票
  1. 要在 Windows 上创建虚拟环境,请使用 python -m venv
  2. 要在 Windows 上激活虚拟环境,请使用 .nv_name\Scripts ctivate.bat **请注意 Windows 上的斜杠。
  3. 要在 Windows 上停用虚拟环境,请使用 .nv_name\Scripts\deactivate.bat **请注意斜杠
© www.soinside.com 2019 - 2024. All rights reserved.