Sha*_*nde 3 python powershell virtualenv
我刚刚开始使用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'
Run Code Online (Sandbox Code Playgroud)
我使用该powershell -ExecutionPolicy ByPass -File venv\Scripts\activate.ps1
命令来执行,activate.ps1
因为正常执行它,我收到一些安全错误。那么,我做错了什么?打印的可执行文件的路径是我系统中的路径,而它应该是venv
文件夹内的可执行文件的路径。此外,在pip install
任何包装上,它都表示满足要求。我应该做什么来激活环境?
我正常执行文件时遇到的错误是:
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
Run Code Online (Sandbox Code Playgroud)
设置和使用虚拟环境:
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 />
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4466 次 |
最近记录: |