问题描述
我刚刚启动了一个新的python项目,并通过在终端中运行virtualenv venv
在项目文件夹中创建了一个venv.但是,当我运行venv/bin/activate
时,出现权限被拒绝错误.
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.
我尝试过
sudo chown -R user:user project/venv
但我明白了
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?
我在Mac上.
推荐答案
您需要运行
. venv/bin/activate
或
source venv/bin/activate
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.
有人在评论中问到.
命令.从 bash手册页:
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.
简而言之,.
是内置的shell,与source
内置的含义相同.
In short, .
is a shell built-in that means the same thing as the source
built-in.
这篇关于激活venv时权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!