[英]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
身份運行它時,一切正常。 所有目錄和文件分別具有0755
或0644
權限。
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可能因此錯誤而失敗的兩個原因。
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.