为什么在激活虚拟环境时会出现语法错误?
Why do I get a syntax error when activating a virtual environment?
我想为 Flask 应用程序创建一个虚拟环境,但在尝试激活它时出现此错误:
C:\Users\jessa\Desktop\travaux-pratiques\tp4-web-bbelzile\depart>python ./env/Scripts/activate
File "./env/Scripts/activate", line 4
deactivate (){
^
SyntaxError: invalid syntax
这不是我第一次尝试制作环境,但这是我第一次收到此错误。
激活 Flask 虚拟环境时出现问题。
您可以使用
激活
cd /env/script
activate.bat
或者您可以使用 Powershell 激活
source env/bin/activate
这里:
C:\...\depart>python ./env/Scripts/activate
您正在尝试 运行 激活脚本 作为 Python script/file。这就是为什么您会收到语法错误的原因,因为它不是 Python 文件,不应该 运行 带有 Python 解释器。
Once a virtual environment has been created, it can be “activated” using a script in the virtual environment’s binary directory. The invocation of the script is platform-specific (<venv>
must be replaced by the path of the directory containing the virtual environment):
Windows | cmd.exe | C:\> <venv>\Scripts\activate.bat
| PowerShell | PS C:\> <venv>\Scripts\Activate.ps1
(我假设你是根据路径Windows激活它)
我想为 Flask 应用程序创建一个虚拟环境,但在尝试激活它时出现此错误:
C:\Users\jessa\Desktop\travaux-pratiques\tp4-web-bbelzile\depart>python ./env/Scripts/activate
File "./env/Scripts/activate", line 4
deactivate (){
^
SyntaxError: invalid syntax
这不是我第一次尝试制作环境,但这是我第一次收到此错误。
激活 Flask 虚拟环境时出现问题。
您可以使用
激活cd /env/script
activate.bat
或者您可以使用 Powershell 激活
source env/bin/activate
这里:
C:\...\depart>python ./env/Scripts/activate
您正在尝试 运行 激活脚本 作为 Python script/file。这就是为什么您会收到语法错误的原因,因为它不是 Python 文件,不应该 运行 带有 Python 解释器。
Once a virtual environment has been created, it can be “activated” using a script in the virtual environment’s binary directory. The invocation of the script is platform-specific (
<venv>
must be replaced by the path of the directory containing the virtual environment):Windows | cmd.exe | C:\> <venv>\Scripts\activate.bat | PowerShell | PS C:\> <venv>\Scripts\Activate.ps1
(我假设你是根据路径Windows激活它)