OS X Lion上Python及其包的正确权限

0 投票
3 回答
677 浏览
提问于 2025-04-17 08:44

我现在使用的是 OS X Lion(之前是 Leopard,经历了两次升级)。OS X Lion 自带 Python 2.7。在某个时候,我觉得 Python 和它的包是可以正常一起工作的(可能是在我升级到 Lion 之前)。

我可以以普通用户身份运行 Python。但是,当我导入一些包或者尝试运行 easy_install 时,就会出现以下错误。

system:distutils $ python
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import zope
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/zope/__init__.py", line 1, in <module>
    __import__('pkg_resources').declare_namespace(__name__)
  File "build/bdist.linux-i686/egg/pkg_resources.py", line 698, in <module>
    class Environment(object):
  File "build/bdist.linux-i686/egg/pkg_resources.py", line 701, in Environment
    def __init__(self, search_path=None, platform=get_supported_platform(), python=PY_MAJOR):
  File "build/bdist.linux-i686/egg/pkg_resources.py", line 96, in get_supported_platform
    plat = get_build_platform(); m = macosVersionString.match(plat)
  File "build/bdist.linux-i686/egg/pkg_resources.py", line 222, in get_build_platform
    plat = get_platform()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/util.py", line 165, in get_platform
    "Don't know machine value for archs=%r"%(archs,))
ValueError: Don't know machine value for archs=()
>>> ^D
system:distutils $

当我以管理员身份或者用 sudo 命令运行时,一切都正常。所有的目录和文件权限分别是 07550644

那么,在 OS X Lion 上,Python 和它的包的权限应该是什么样的,才能让普通用户使用呢?我现在的权限配置是默认的吗,还是我在某个地方搞错了权限设置。

我知道我可以去 /System/Library/... 和 /Library/Python/... 目录下,把所有权和权限改成我的。但是,这似乎不是正确的解决办法。

3 个回答

0

如果你是通过搜索这个错误而来到这里的,可能这个问题并不是权限方面的。实际上,这个问题可能是因为Python用来判断(苹果)平台的环境变量设置不正确。

相关的设置包括至少以下这些:

'CFLAGS', 'LDFLAGS', 'CPPFLAGS', 'BASECFLAGS', 'BLDSHARED', 'LDSHARED', 'CC', 'CXX', 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS', 'PY_CORE_CFLAGS'

你可以查看Python标准库中的_osx_support.py文件,特别是里面的get_platform_osx函数;所有的信息都在那儿。

0

你的Python环境有点不对劲。在我的Lion(10.7.3)系统上,苹果自带的Python 2.7有这个标识,而且导入Zope没有问题:

$ /usr/bin/python2.7
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import zope
>>>

也许你安装了Lion的某些预发布版本?

0

经过一段时间的挣扎和反复的沮丧,我发现了两个导致easy_install出错的原因。

  1. 我需要安装XCode(我已经安装了)
  2. 我简单地查看了util.py中的代码,找到了出错的那一行,并修改了结果。

这样做效果很好。我现在再也没有遇到过那个错误。我把解决方案的差异放在下面。请注意,我选择了'intel'作为machine类型,因为在OS X Lion中,所有对PPC的支持都被移除了。

希望这能帮助到其他人。

wintermute:distutils $ pwd
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils
wintermute:distutils $ diff -U 5  util.py.bad util.py
--- util.py.bad 2012-03-03 15:30:39.000000000 -0500
+++ util.py 2012-03-03 15:32:21.000000000 -0500
@@ -159,12 +159,13 @@
                 elif archs == ('ppc64', 'x86_64'):
                     machine = 'fat64'
                 elif archs == ('i386', 'ppc', 'ppc64', 'x86_64'):
                     machine = 'universal'
                 else:
-                    raise ValueError(
-                       "Don't know machine value for archs=%r"%(archs,))
+                    machine = 'intel'
+                    #raise ValueError(
+                    #   "Don't know machine value for archs=%r"%(archs,))

             elif machine == 'i386':
                 # On OSX the machine type returned by uname is always the
                 # 32-bit variant, even if the executable architecture is
                 # the 64-bit variant
wintermute:distutils $ 

撰写回答