【问题标题】:Proper permissions for Python and packages on OS X LionOS X Lion 上的 Python 和包的适当权限
【发布时间】:2011-12-20 22:52:21
【问题描述】:

我正在运行 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 $

当我以 root 或 sudo 运行它时,一切正常。所有目录和文件分别具有0755 或0644 权限。

对于 Python 及其在 OS X Lion 上的包应该有什么权限,以便您可以像普通用户一样使用它?我的权限当前配置的方式是默认的,还是我一路搞砸了权限。

我意识到我可以通过 /System/Library/... 和 /Library/Python/... 目录并将所有权和权限更改给我。但这似乎不是正确的解决方案。

【问题讨论】:

    标签: python macos permissions osx-lion


    【解决方案1】:

    在挣扎了一段时间后,一再感到沮丧,我想出了两个原因 easy_install 可能会因此错误而失败。

    1. 我需要安装 XCode(我已经安装了)
    2. 我只是通过util.py 中的代码找到产生错误的行,并更改了结果。

    这非常有效。我现在从未收到该错误。我已将差异放在下面以获得解决方案。请注意,我为 machine 类型选择了 'intel',因为在 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 $ 
    

    【讨论】:

      【解决方案2】:

      您的 Python 设置有些不寻常。在我的 Lion (10.7.3) 系统上,Apple 提供的 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 部分的预发布版本?

      【讨论】:

      • 我毫不怀疑你是对的。我拥有与您相同的 Python 版本。我是从雪豹升级的。你有干净安装的Lion吗?我认为一个问题可能是以前我没有安装 XCode。
      • 我的机器从 SL 升级,并全新安装了 Lion,据我所知,我从未见过 Apple 的 /usr/bin/python2.7 的构建日期不是 2011 年 7 月 31 日。
      • 我不知道为什么我的构建日期不是 2011 年 7 月 31 日,但是很多其他人也有我的构建日期。我没有使用预发布版本,并且正在运行 Lion 10.7.3。我昨天也刚升级到最新版本的 XCode。
      【解决方案3】:

      对于通过谷歌搜索错误来到这里的任何人,这也可能不是权限问题。相反,它可能是因为 Python 用于确定 (Apple) 平台的环境变量设置不正确。

      相关标志至少包括:

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

      查看 Python stdlib 的 _osx_support.py 文件,尤其是 get_platform_osx 函数;都在那里。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-02-03
        • 2013-09-07
        • 2012-04-05
        • 2012-12-11
        • 2011-10-13
        • 1970-01-01
        • 2012-02-21
        相关资源
        最近更新 更多