Permission denied when activating venv

PythonMacos

Python Problem Overview


I just started a new python project and created a venv inside the project folder by running virtualenv venv in the terminal. However, when I run venv/bin/activate I get a permission denied error.

I have tried

sudo chown -R user:user project/venv

but I get

chown: user: illegal group name

I have set these venvs up a ton of times and never had the issue. Is there anything else I can try?

I am on a Mac.

Python Solutions


Solution 1 - Python

You need to run

. venv/bin/activate

or

source venv/bin/activate

The activate file is deliberately not executable because it must be sourced.

It must be sourced because it needs to make changes to the environment. If it is run as a script, it will only make changes to the environment of the child process used to run the script.

Someone in the comments asked about the . command. From the man page for bash:

    .  filename [arguments]
   source filename [arguments]
          Read  and execute commands from filename in the current shell
          environment and return the exit status of the last command
          executed from filename.

In short, . is a shell built-in that means the same thing as the source built-in.

Solution 2 - Python

On my VSC, I used these and it worked.

python3 -m venv .venv

source .venv/bin/activate

Solution 3 - Python

I had the same problem and this worked for me:. venv/bin/activate

Solution 4 - Python

enter image description hereFrom within the virtual environment folder can type:

source ./bin/activate

and yes if you run into the permission issue then go one folder up and do the source ./foldervirtualenvironment/bin/activate

Solution 5 - Python

source venv/bin/activate

source venv/bin/activate

activated successfully 'source' command need to add before full path of activation file.

Ex.

  • Source your_project_folder_path/venv/bin/activate

**

if you're inside project folder then following command-

  • Source venv/bin/activate

.

Solution 6 - Python

Basically, it's looking for permission to execute activate on the created folder path.

On the root give below permissions command on the desired path where activate is located

sudo chmod -R 755 ~/tensorflow/* # or whatever the target structure 

This will extend all the permissions including Read/Write/Execute and group

then execute ~/bin/activate

Solution 7 - Python

From the command line root enter:

source /home/<your_username>/<app_folder>/<venv_name>/bin/activate

Worked for me

Solution 8 - Python

go to activate file right click and open properties-->permissions

and check Execute

open this image:

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3088202View Question on Stackoverflow
Solution 1 - PythonDavid CullenView Answer on Stackoverflow
Solution 2 - PythonfrancescowangView Answer on Stackoverflow
Solution 3 - PythonCyebukayireView Answer on Stackoverflow
Solution 4 - PythonFayazView Answer on Stackoverflow
Solution 5 - PythonAlauddin SabariView Answer on Stackoverflow
Solution 6 - PythonneiodavinceView Answer on Stackoverflow
Solution 7 - PythonJulianView Answer on Stackoverflow
Solution 8 - PythonAlaskry ibrahimView Answer on Stackoverflow