BenBel
BenBel

Reputation: 49

Why do I get a syntax error when activating a virtual environment?

I want to make a virtual environment for a Flask application and I get this error when I try to activate it:

C:\Users\jessa\Desktop\travaux-pratiques\tp4-web-bbelzile\depart>python ./env/Scripts/activate  
  File "./env/Scripts/activate", line 4
    deactivate (){
                 ^
SyntaxError: invalid syntax

It's not the first time that I try to make an env but it is the first time that I get this error.

Upvotes: 1

Views: 4181

Answers (2)

Gino Mempin
Gino Mempin

Reputation: 29660

Here:

C:\...\depart>python ./env/Scripts/activate

You are trying to run the activation script as a Python script/file. That's not a Python script and should not be run with a Python interpreter.

As indicated in the virtual environment docs:

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

(I'm assuming you are activating it on Windows based on the path)

Upvotes: 4

user9573798
user9573798

Reputation:

There is a problem while activating your Flask virtual environment.

You can activate by using

cd /env/script
activate.bat

Or you can activate using your Powershell

source env/bin/activate

Upvotes: 1

Related Questions