Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission denied when activating venv

Tags:

python

macos

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.

like image 604
user3088202 Avatar asked Aug 07 '17 20:08

user3088202


People also ask

Do I have to activate VENV every time?

Activating the virtualenv gives you convenience. It is never required. Activating makes the PATH update stick until you deactivate again, and that can be convenient.

How do I exit VENV?

You can exit from the virtualenv using exit command, or by pressing Ctrl+d.


2 Answers

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.

like image 78
David Cullen Avatar answered Sep 23 '22 14:09

David Cullen


On my VSC, I used these and it worked.

python3 -m venv .venv  source .venv/bin/activate 
like image 29
francescowang Avatar answered Sep 22 '22 14:09

francescowang