[英]How to activate virtual environment from Windows 10 command prompt
我正在嘗試使用 Windows 10 命令提示符創建並激活虛擬環境。 我知道 virtualenv 安裝正確,因為命令
virtualenv venv
作品。 我已經導航到我的 virtualenv 下載,Downloads\venv\Scripts,並正在嘗試激活我的虛擬環境 venv。 我試過了
venv activate
這不起作用,因為 Windows 無法將 venv 識別為命令。 我也試過
virtualenv venv activate
這也不起作用,因為 virtualenv 說“venv activate”不是一個有效的論點。
使用虛擬環境的 Scripts 目錄中的activate
腳本:
> venv\Scripts\activate
這將激活您的虛擬環境,您的終端將根據您所在的目錄如下所示:
(venv) C:\Users\acer\Desktop>
我希望這會有所幫助!
如果您使用virtualenvwrapper-win
並使用 DOS 命令提示符(而不是例如 Powershell),則使用以下命令創建新的 virtualenv:
mkvirtualenv myenv
並使用激活
workon myenv
您應該定義環境變量WORKON_HOME
以指向您希望WORKON_HOME
環境駐留的位置。
如果你安裝了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中的虛擬環境
當您使用“virtualenv”創建環境時,它會在源自您運行第一個命令的目錄的腳本文件夾中保存一個“activate.bat”文件。 例如,如果您從C:/Users/Name/Documents/...
運行命令virtualenv env
,則 .bat 將位於C:/Users/Name/Documents/.../env/scripts/activate.bat
。 你可以從那里運行它。
只需使用以下命令激活您的 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
這從 Anaconda 提示對我有用,
.\\myvenv\\Scripts\\activate.bat
從您擁有虛擬環境的目錄(例如myenv
)
您需要運行以下命令: .\\myenv\\Scripts\\activate
只需鍵入以下命令即可激活 windows 的虛擬環境。
venv\Scripts\activate
python test.py
如果您是 windows 用戶,只需編寫 venv\Scripts\activate
從 cmd
call venv/Scripts/activate
確保 Python Scripts 文件夾位於您的環境變量中。
通常路徑是:“C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python37-32\\Scripts”(根據你的python版本將“admin”改為你的windows用戶名和“Python37-32”路徑)
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...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.