Python OSError: [Errno 13] 权限被拒绝:
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31095977/
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
OSError: [Errno 13] Permission denied:
提问by auto
I am trying to install a library package to python but I get the following error:
我正在尝试将库包安装到 python,但出现以下错误:
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/PackageName'
I've looked online and tried the following, but it doesn't seem to work:
我在网上查看并尝试了以下方法,但似乎不起作用:
chown -R $USER /Library/Python/2.7/site-packages/pync
and also:
并且:
chown -R $USER /Library/Python/2.7
采纳答案by James Andariese
The problem with your first attempt is that you won't have created pync for the chmod to work yet.
您第一次尝试的问题是您还没有为 chmod 创建 pync 工作。
chown: /Library/Python/2.7/site-packages/pync: No such file or directory
The problem with your second attempt is that $vdixon is a variable expansion -- it will evaluate to the empty string in most cases and result in help being printed on a mac.
您第二次尝试的问题在于 $vdixon 是一个变量扩展——在大多数情况下它会评估为空字符串并导致帮助打印在 mac 上。
usage: chown [-fhv] [-R [-H | -L | -P]] owner[:group] file ...
chown [-fhv] [-R [-H | -L | -P]] :group file ...
You don't actually show what went wrong in your question so it's hard to say but if it matches the above, we're on the right track.
您实际上并没有显示您的问题出了什么问题,所以很难说,但如果它与上述相符,我们就在正确的轨道上。
All that being said, you don't want to change ownership of your system Python. Instead, you might want to have the root user install the module. I'll follow up with a way that you can avoid even that but first, let's solve the problem at hand.
尽管如此,您不想更改系统 Python 的所有权。相反,您可能希望让 root 用户安装该模块。我会跟进一种方法,您甚至可以避免这种情况,但首先,让我们解决手头的问题。
To solve your particular issue try whichever one most closely matches what you were doing originally:
要解决您的特定问题,请尝试最接近您最初所做的操作:
sudo python setup.py install
or
或者
sudo pip install <package name>
or
或者
sudo easy_install <package name>
Now, these will have installed the package and you can stop reading.
现在,这些将安装软件包,您可以停止阅读。
... but let's say you want to avoid having to pollute your system Python installation with modules that may not be compatible with others. For this, the Python community uses virtualenv. Virtualenv still generally is installed in the system Python site-packages but that's considered the last thing you'll ever have to. Here's how you might do what you're trying to do with virtualenv instead:
...但是假设您想避免使用可能与其他模块不兼容的模块污染您的系统 Python 安装。为此,Python 社区使用 virtualenv。Virtualenv 通常仍然安装在系统 Python 站点包中,但这被认为是您最不需要的东西。以下是您可以使用 virtualenv 执行的操作:
sudo pip install virtualenv
virtualenv my_app_virtualenv
. my_app_virtualenv/bin/activate
pip install <package name>
# (or python setup.py install or easy_install <package name>)
Whenever you want to use the dependency you've installed in the virtualenv again, you'll run:
每当您想再次使用已安装在 virtualenv 中的依赖项时,您将运行:
. my_app_virtualenv/bin/activate
There are further improvements to be made to the process with virtualenvwrapper if this is a common thing you're doing.
如果这是您正在做的常见事情,则可以使用 virtualenvwrapper 对流程进行进一步改进。
Read more at http://docs.python-guide.org/en/latest/dev/virtualenvs/
在http://docs.python-guide.org/en/latest/dev/virtualenvs/阅读更多内容