繁体   English   中英

对OS X Lion上的Python和软件包的适当权限

[英]Proper permissions for Python and packages on OS X Lion

我正在运行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身份运行它时,一切正常。 所有目录和文件分别具有07550644权限。

OS X Lion上的Python及其软件包的权限应该是什么,以便您可以以普通用户身份使用它? 是当前配置我的权限的默认方式,还是我一路搞乱了权限。

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

对于通过谷歌搜索错误来这里的任何人,也有可能这不是权限问题。 而是由于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函数; 都在那里。

经过一段时间的努力,并不断感到沮丧,我发现了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 $ 

您的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的预发行版本?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM