簡體   English   中英

virtualenv 沒有激活虛擬環境

[英]virtualenv not activating the virtual enviroment

我剛剛開始使用virtualenv並且對它沒有深入的了解。 我按照網站上的說明創建了文件夾,然后執行了activate.ps1文件。 它執行時沒有任何錯誤,但是當我嘗試使用 python 時,它仍然使用我系統中安裝的 python 而不是虛擬環境文件夾中的 python。 以下是我使用的命令:

PS A:\Code\IIITH\image-processing-iiith\SRIP> virtualenv venv
Using base prefix 'c:\\users\\shind\\appdata\\local\\programs\\python\\python37'
New python executable in A:\Code\IIITH\image-processing-iiith\SRIP\venv\Scripts\python.exe
Installing setuptools, pip, wheel...
done.
PS A:\Code\IIITH\image-processing-iiith\SRIP> powershell -ExecutionPolicy ByPass -File venv\Scripts\activate.ps1
PS A:\Code\IIITH\image-processing-iiith\SRIP> python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import sys
>>> os.path.dirname(sys.executable)
'C:\\Users\\shind\\AppData\\Local\\Programs\\Python\\Python37'

我使用了powershell -ExecutionPolicy ByPass -File venv\\Scripts\\activate.ps1命令來執行activate.ps1因為正常執行它,我收到了一些安全錯誤。 那么,我做錯了什么? 打印的可執行文件的路徑是我系統中的路徑,而它應該是venv文件夾中的可執行文件。 此外,在pip install any 包上,它表示滿足要求。 我該怎么做才能激活環境?

我在正常執行文件時遇到的錯誤是:

PS A:\Code\IIITH\image-processing-iiith\SRIP>  venv\Scripts\activate.ps1
venv\Scripts\activate.ps1 : File A:\Code\IIITH\image-processing-iiith\SRIP\venv\Scripts\activate.ps1 cannot be loaded
because running scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:2
+  venv\Scripts\activate.ps1
+  ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

設置和使用虛擬環境:

PS /> python -m venv .venv
PS /> Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
PS /> ./.venv/Scripts/Activate.ps1
(.venv) PS /> pip install -r requirements.txt

[...]

(.venv) PS />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM