我正在尝试使用 Windows 10 命令提示符创建并激活虚拟环境。我知道 virtualenv 已正确安装,如命令所示
virtualenv venv
有效。我已导航到我的 virtualenv 下载,下载 env\Scripts,并尝试激活我的虚拟环境 venv。我试过了
venv activate
这不起作用,因为 Windows 无法将 venv 识别为命令。我也尝试过
virtualenv venv activate
这也不起作用,因为 virtualenv 说“venv activate”不是有效的参数。
使用虚拟环境的 Scripts 目录中的
activate
脚本:
> venv\Scripts\activate
这将激活您的虚拟环境,您的终端将如下所示,具体取决于您所在的目录:
(venv) C:\Users\acer\Desktop>
我希望这有帮助!
从命令(
cmd
)提示:
call venv/Scripts/activate
如果您使用
virtualenvwrapper-win
,并使用 DOS 命令提示符(而不是 Powershell),则使用以下命令创建新的 virtualenv:
mkvirtualenv myenv
并使用
激活workon myenv
您应该定义环境变量
WORKON_HOME
来指向您希望 virtualenv 驻留的位置。
如果您已经安装了
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
进入cmd中创建虚拟环境的文件夹,然后 输入命令
.\venv\Scripts\activate
它将激活 Windows 中的虚拟环境
从您拥有虚拟环境的目录(例如
myenv
)
您需要运行以下命令:
.\myenv\Scripts\activate
当您使用“virtualenv”创建环境时,它会将“activate.bat”文件保存在源自您运行第一个命令的目录的脚本文件夹中。例如,如果您从
virtualenv env
运行命令 C:/Users/Name/Documents/...
,则 .bat 将位于 C:/Users/Name/Documents/.../env/scripts/activate.bat
中。您可以从那里运行它。
这对 Anaconda 提示符下的我有用,
.\\myvenv\\Scripts\\activate.bat
确保 Python Scripts 文件夹位于您的环境变量中。
通常路径是:“C:\Users dmin\AppData\Local\Programs\Python\Python37-32\Scripts” (根据您的Python版本将“admin”更改为您的Windows用户名和“Python37-32”路径)
您可以使用命令激活您的 virtualenv:
workon myenvname
您还可以创建这样的命令行脚本 -
@echo off
CD\
CD "C:\Users\[user name]\venv\Scripts"
start activate.bat
start jupyter notebook
将其保存在扩展名为“.cmd”的记事本文件中。 你准备好出发了吗
如果您安装了 anaconda,则打开 anaconda 终端 并输入
> conda env list # for list of environment you already have
> conda activate {env_name} # to activate the environment
您好,我也遇到了同样的问题。 所以这里是我为了在 Windows 中创建虚拟环境而没有任何错误所遵循的步骤:
注意:- “.”之间没有空格。和“”
谢谢!
首先打开命令行。然后将 active.bat 文件从该地址拖放到您的命令行中。
地址:
your virtual environment name/Scripts/
python -m virtualenv
"You must provide a DEST_DIR"
python -m venv demodjango("demodjango is file name)"
activate.bat
pip install django
django-admin.py startproject demo1
(demo1是我的项目)python manage.py runserver
Performing system checks...