我正在运行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
权限。
OS X Lion上的Python及其软件包的权限应该是什么,以便您可以将其用作普通用户?我的权限当前配置的方式是默认方式,还是我在整个过程中搞砸了权限。
我意识到我可以浏览/ System / Library / ...和/ Library / Python / ...目录并更改对我的所有权和权限。但这似乎不是正确的解决方案。
答案 0 :(得分:0)
经过一段时间的挣扎,并且反复受挫,我想出了easy_install因此错误而失败的两个原因。
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 $
答案 1 :(得分:0)
您的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的预发布版本?
答案 2 :(得分:0)
对于通过Google搜索错误来到这里的任何人,也可能这不是权限问题。相反,它可能会发生,因为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函数;它就在那里。