注意:人们将其标记为另一个问题的重复,但事实并非如此。我的virtualenv出现了一些问题,我无法解决。它可能与Visual Studio的设置方式有关。
尝试在Windows上激活虚拟环境时遇到问题。你如何执行$ venv\Scripts\activate
?这应该是从命令提示符还是Powershell?我已经使用Visual Studio作为我的IDE。它为您创建了一个具有基本烧瓶应用程序的VS解决方案。在创建应用程序的过程中,它会要求您创建一个虚拟环境。它在类似于本教程所示目录的目录中创建该虚拟环境。\venv\Scripts
退出,但没有名为“激活”的文件或可执行文件。
这是“脚本”文件夹的内容:
api-ms-win-core-console-l1-1-0.dll api-ms-win-core-console-l1-1-0.dll
api-ms-win-core-debug-l1-1-0.dll
api-ms-win-core-errorhandling-l1-1-0.dll
api-ms-win-core-file-l1-1-0.dll api-ms-win-core-file-l1-2-0.dll
api-ms-win-core-file-l2-1-0.dll api-ms-win-core-file-l2-1-0.dll
api-ms-win-core-heap-l1-1-0.dll api-ms-win-core-heap-l1-1-0.dll
api-ms-win-core-libraryloader-l1-1-0.dll
api-ms-win-core-localization-l1-2-0.dll
api-ms-win-core-Memory-l1-1-0.dll api-ms-win-core-namedpipe-l1-1-0.dll
api-ms-win-core-processenvironment-l1-1-0.dll
api-ms-win-core-processthreads-l1-1-0.dll
api-ms-win-core-processthreads-l1-1-1.dll
api-ms-win-core-profile-l1-1-0.dll
api-ms-win-core-rtlsupport-l1-1-0.dll
api-ms-win-core-string-l1-1-0.dll api-ms-win-core-string-l1-1-0.dll
api-ms-win-core-synch-l1-2-0.dll api-ms-win-core-synch-l1-2-0.dll
api-ms-win-core-timezone-l1-1-0.dll api-ms-win-core-timezone-l1-1-0.dll
api-ms-win-crt-conio-l1-1-0.dll api-ms-win-crt-con1-1-.dll
api-ms-win-crt-environment-l1-1-0.dll
api-ms-win-crt-filesystem-l1-1-0.dll api-ms-win-crt-file-l1-1-0.dll
api-ms-win-crt-locale-l1-1-0.dll api-ms-win-crt-math-l1-1-0.dll
api-ms-win-crt-multibyte-l1-1-0.dll api-ms-win-crt-private-l1-1-0.dll
api-ms-win-crt-process-l1-1-0.dll api-ms-win-crt-process-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll api-ms-win-crt-string-l1-1-0.dll
api-ms-win-crt-time-l1-1-0.dll api-ms-win-crt-utility-l1-1-0.dll
concrt140.dll msvcp140.dll pyexpat.pyd python.exe python3.dll
python36.dll pythoncom36.dll pythonw.exe pywintypes36.dll select.pyd
sqlite3.dll tcl86t.dll tk86t.dll ucrtbase.dll unicodedata.pyd
vccorlib140.dll vcomp140.dll vcruntime140.dll winsound.pyd
xlwings32.dll xlwings64.dll
_asyncio.pyd
_bz2.pyd
_ctypes.pyd
_ctypes_test.pyd
_decimal.pyd
_elementtree.pyd
_hashlib.pyd
_lzma.pyd
_msi.pyd
_multiprocessing.pyd
_overlapped.pyd
_socket.pyd
_sqlite3.pyd
_ssl.pyd
_testbuffer.pyd
_testcapi.pyd
_testconsole.pyd
_testimportmultiple.pyd
_testmultiphase.pyd
_tkinter.pyd
我一直到数据迁移部分,但是在这里我需要运行(venv) $ flask db migrate
我不知道如何进入虚拟环境来运行它。
这是我通过PowerShell在Windows上安装python时的CheatSheet。
首先从https://www.python.org/downloads/安装python 2.7x
然后将Python and Scripts文件夹添加到path变量(系统范围)
# Add Python and Python Scripts to path
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
$PythonPath = "C:\Python27"
$PythonScriptsPath = "C:\Python27\Scripts"
if ($env:Path -notlike "*$PythonPath*") {
$env:Path = $env:Path + ";$PythonPath"
}
if ($env:Path -notlike "*$PythonScriptsPath*") {
$env:Path = $env:Path + ";$PythonScriptsPath"
}
# Save to machine path
[Environment]::SetEnvironmentVariable( "Path", $env:Path, [System.EnvironmentVariableTarget]::Machine )
# Check machine path
[System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
然后通过pip安装virtualenv
pip install virtualenv
激活虚拟环境
virtualenv venv
. .\venv\Scripts\activate
如果使用Powershell,则该
activate
脚本应遵循系统上的执行策略。在Windows 7上,默认情况下,系统的执行策略设置为Restricted
。为了使用脚本,您可以将系统的执行策略放宽到AllSigned
,这意味着必须对系统上的所有脚本进行数字签名才能执行。以管理员身份运行:Set-ExecutionPolicy AllSigned
停用虚拟环境
deactivate
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句