注意:人们已将此标记为另一个问题的副本,但事实并非如此。关于我的virtualenv有一些东西,我无法解决它。这可能与Visual Studio如何设置它有关。
我一直在关注这个优秀的tutorial on flask
当我尝试在Windows上激活虚拟环境时遇到了问题。你如何执行$ venv\Scripts\activate
?这应该来自命令提示符还是Powershell?我使用Visual Studio作为我的IDE。它为您创建了一个VS解决方案,它具有一个基本的烧瓶应用程序。在创建应用程序的过程中,它会要求您创建虚拟环境。它在类似于教程中显示的目录中创建该虚拟环境。 \venv\Scripts
退出,但它没有名为“activate”的文件或可执行文件。
这是Scripts文件夹的内容:
api-ms-win-core-console-l1-1-0.dll api-ms-win-core-datetime-l1-1-0.dll
API-MS-双赢芯调试l1-1-0.dll
API-MS-双赢芯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-handle-l1-1-0.dll
api-ms-win-core-heap-l1-1-0.dll api-ms-win-core-interlocked-l1-1-0.dll
API-MS-双赢芯libraryloader-l1-1-0.dll
API-MS-双赢芯定位-l1-2-0.dll
api-ms-win-core-memory-l1-1-0.dll api-ms-win-core-namedpipe-l1-1-0.dll
API-MS-双赢芯processenvironment-l1-1-0.dll
API-MS-双赢芯processthreads-l1-1-0.dll
API-MS-双赢芯processthreads-l1-1-1.dll
API-MS-双赢芯轮廓l1-1-0.dll
API-MS-双赢芯rtlsupport-l1-1-0.dll
api-ms-win-core-string-l1-1-0.dll api-ms-win-core-synch-l1-1-0.dll
api-ms-win-core-synch-l1-2-0.dll api-ms-win-core-sysinfo-l1-1-0.dll
api-ms-win-core-timezone-l1-1-0.dll api-ms-win-core-util-l1-1-0.dll
api-ms-win-crt-conio-l1-1-0.dll api-ms-win-crt-convert-l1-1-0.dll
API-MS-双赢CRT-环境l1-1-0.dll
api-ms-win-crt-filesystem-l1-1-0.dll api-ms-win-crt-heap-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-runtime-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
我一直到data migration section,但在这里我需要运行(venv) $ flask db migrate
我对如何进入虚拟环境以运行它感到茫然。
答案 0 :(得分:5)
当我通过PowerShell在Windows上安装python时,这是我的CheatSheet。
首先从https://www.python.org/downloads/
安装python 2.7x然后将Python和Scripts文件夹添加到路径变量(系统范围)
# 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
virtualenv venv
. .\venv\Scripts\activate
如果使用Powershell,则
activate
脚本受制于系统上的执行策略。默认情况下,在Windows 7上,系统的执行策略设置为Restricted
。为了使用该脚本,您可以将系统的执行策略放宽到AllSigned
,这意味着系统上的所有脚本都必须经过数字签名才能执行。管理员运行:Set-ExecutionPolicy AllSigned
停用virtualenv
deactivate
答案 1 :(得分:-1)
执行cd pat_to_env / Scripts,然后运行activate命令。