4

我正在使用 zc.buildout,当我尝试运行引导程序(第一次在新计算机上)时,我收到以下错误:

>> python2.7 bootstrap.py

Traceback (most recent call last):
  File "bootstrap.py", line 158, in <module>
    import pkg_resources
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/../../Extras/lib/python/pkg_resources.py", line 698, in <module>
    class Environment(object):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/../../Extras/lib/python/pkg_resources.py", line 701, in Environment
    def __init__(self, search_path=None, platform=get_supported_platform(), python=PY_MAJOR):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/../../Extras/lib/python/pkg_resources.py", line 99, in get_supported_platform
    plat = 'macosx-%s-%s' % ('.'.join(_macosx_vers()[:2]), m.group(3))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/../../Extras/lib/python/pkg_resources.py", line 209, in _macosx_vers
    _cache.append(mac_ver()[0].split('.'))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/platform.py", line 803, in mac_ver
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/platform.py", line 780, in _mac_ver_xml
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plistlib.py", line 78, in readPlist
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plistlib.py", line 406, in parse
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plistlib.py", line 418, in handleEndElement
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plistlib.py", line 452, in end_key
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plistlib.py", line 436, in getData
LookupError: unknown encoding: ascii

有没有人见过这个或知道如何解决它?它似乎与获取我的操作系统的当前版本有关。我的操作系统是 Mac 10.8.2。

谢谢!

4

4 回答 4

3

正如 Vitaly 回答的那样,问题确实是原始 .py 文件丢失了/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/(干净安装中只有 .pyc 文件)。具体来说,这些文件必须存在才能使 bootstrap.py 成功:

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/__init__.py
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py

您可以从 virtualenv 或其他计算机复​​制它们。

于 2013-02-05T09:05:04.247 回答
2

安装 Xcode 命令行工具为我解决了这个问题,尽管我无法解释原因。你可以从 Xcode 安装这些

Preferences -> Downloads

或从Apple Developers 下载页面

于 2013-02-08T15:07:58.490 回答
2

检查是否/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7包含未编译的模块 (*.py)。默认情况下它们是缺失的,这就是问题所在。

于 2012-11-28T07:00:34.053 回答
1

这似乎是 Mountain Lion 唯一的问题,并且只有在您的 python 是全新安装的情况下(或者报告似乎表明)。

解决方法是使用-S开关运行 python:

python2.7 -S bootstrap.py

或者创建一个 virtualenv,然后bootstrap.py使用 virtualenv python 运行脚本。

于 2012-11-19T13:23:48.363 回答