【发布时间】:2023-04-01 12:51:01
【问题描述】:
首先,我目前正在运行 OSX 10.9.1 和 Python 2.7。
我想使用easy_install(在本例中为pip)安装Python 包。首先我尝试:
easy_install pip
然后我收到一条错误消息,指出我没有对 site-packages 目录的写入权限。没问题:
sudo easy_install pip
一切正常下载。下面是我安装pip后的Bash会话:
$ pip
-bash: /usr/local/bin/pip: Permission denied
$ cd /usr/local/bin/pip
$ ls -l
...
-rwx------ 1 root admin 275 Jan 10 11:05 pip
...
$ chmod 754 pip
chmod: Unable to change file mode on pip: Operation not permitted
$ sudo chmod 754 pip
$ pip
Traceback (most recent call last):
File "./pip", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.macosx-10.8-intel/egg/pkg_resources.py", line 3007, in <module>
File "build/bdist.macosx-10.8-intel/egg/pkg_resources.py", line 728, in require
requirements specified when this environment was created, or False
File "build/bdist.macosx-10.8-intel/egg/pkg_resources.py", line 626, in resolve
pkg_resources.DistributionNotFound: pip==1.5
好的,所以也许有些权限仍然搞砸了。这是 Finder 在我查看 /Library/Python/2.7/site-packages/ 时向我显示的内容:
这是ls -l 在查看同一目录时返回的内容:
...
drwx------ 4 root wheel 136 Jan 10 11:24 pip-1.5-py2.7.egg
...
好的,所以我显然没有使用pip 的权限,因为我没有存档文件的执行权限。怎么样:
$ chmod 754 pip-1.5-py2.7.egg
chmod: Unable to change file mode on pip-1.5-py2.7.egg/: Operation not permitted
$ sudo chmod 754 pip-1.5-py2.7.egg
$ pip
Traceback (most recent call last):
File "/usr/local/bin/pip", line 9, in <module>
load_entry_point('pip==1.5', 'console_scripts', 'pip')()
File "build/bdist.macosx-10.8-intel/egg/pkg_resources.py", line 378, in load_entry_point
def get_resource_stream(manager, resource_name):
File "build/bdist.macosx-10.8-intel/egg/pkg_resources.py", line 2565, in load_entry_point
section = line[1:-1].strip()
ImportError: Entry point ('console_scripts', 'pip') not found
我的假设是所有权限都搞砸了,因为我使用了sudo,现在我只是在追逐权限。不过,这可能是错误的。我从来不记得在升级到 OSX 10.9 之前遇到过这个问题。
我的问题是:Unix 系统是否总是使用sudo 执行此操作,即使我是计算机的管理员?有没有办法让我永久纠正这个问题,以便我实际上有权运行已安装的软件包?您认为我的系统中某处的设置不正确吗?
【问题讨论】:
-
理由273不升级到小牛...
-
@Thanizer,你运行
disk utility并修复权限了吗?这可能是一个很好的起点。 chmod 754 也不会削减它,您需要使用 755 并为此拥有owner root、group wheel。 -
@I'L'I,我只是修复了权限无济于事。现在我只是在 Homebrew 中使用 Python 公式,一切似乎都运行良好。不过,我仍然想知道为什么我不能使用 OSX 的原生
easy_install脚本,但没有权限问题。
标签: python macos bash permissions