Python 激活 venv 时权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45554864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Permission denied when activating venv
提问by user3088202
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.
我刚刚开始了一个新的 python 项目,并通过virtualenv venv
在终端中运行在项目文件夹中创建了一个 venv 。但是,当我运行时,出现venv/bin/activate
权限被拒绝错误。
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?
我已经设置了很多次这些 venvs,但从未遇到过这个问题。还有什么我可以尝试的吗?
I am on a Mac.
我在 Mac 上。
回答by David Cullen
You need to run
你需要跑
. venv/bin/activate
or
或者
source venv/bin/activate
The activate
file is deliberately not executable because it must be sourced.
该activate
文件故意不可执行,因为它必须是来源。
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.
简而言之,.
是一个内置的外壳,与内置的含义相同source
。
回答by neiodavince
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
在 root 上,在 activate 所在的所需路径上给出以下权限命令
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
然后执行 ~/bin/activate
回答by Julian
From the command line root enter:
从命令行根输入:
source /home/<your_username>/<app_folder>/<venv_name>/bin/activate
Worked for me
为我工作