Python无法在Mac OSX上找到distutils_path [英] Python can't locate distutils_path on Mac OSX

查看:166
本文介绍了Python无法在Mac OSX上找到distutils_path的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用virtualenv + pip进行python开发.我不确定发生了什么,但是突然每当我尝试运行命令行工具或导入库时,我都会收到以下错误消息:

I've been using virtualenv + pip for python development. I'm not sure what happened, but suddenly whenever I try to run a command-line tool or import libraries, I get this error message:

Traceback (most recent call last):
  File "/Users/kyle/.virtualenvs/fj/bin/pip", line 4, in <module>
    import pkg_resources
  File "/Users/kyle/.virtualenvs/fj/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 698, in <module>
    the platform/python version defined at initialization are added.
  File "/Users/kyle/.virtualenvs/fj/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 701, in Environment
    search_path = sys.path
  File "/Users/kyle/.virtualenvs/fj/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 96, in get_supported_platform
    'Environment', 'WorkingSet', 'ResourceManager',
  File "/Users/kyle/.virtualenvs/fj/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 221, in get_build_platform
    if provDarwin:
  File "/Users/kyle/.virtualenvs/fj/lib/python2.6/distutils/__init__.py", line 14, in <module>
    exec open(os.path.join(distutils_path, '__init__.py')).read()
IOError: [Errno 2] No such file or directory: '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/__init__.py'

据我所知,Python试图在Mac OSX系统版本的Python中找到distutils_path,而不是我的virtualenv版本.

From what I can decipher, Python is trying to find distutils_path in the Mac OSX system version Python, not my virtualenv version like it should be.

不确定为什么突然开始发生这种情况.也许是最近的OSX更新?另一种可能是我的硬盘快要死了,所以Apple给我换了一个新硬盘并运行了Migration Assistant.也许某些东西无法正确传递?

Not sure why this suddenly started happening. Maybe a recent OSX update? Another possibility is that my hard drive was about to die, so Apple gave me a new one and ran Migration Assistant. Maybe something didn't transferred across correctly?

推荐答案

在过渡到OS X 10.7 Lion(从OS X 10.5 Leopard)并使用迁移助手时,遇到了distutils/__init__.py问题.我已经安装了Xcode 3.2.6,从而解决了缺少的install_name_tool问题.

I encountered this distutils/__init__.py problem when transitioning to OS X 10.7 Lion (from OS X 10.5 Leopard) and using Migration Assistant. I've already installed Xcode 3.2.6 -- thus resolving the missing install_name_tool problem.

迁移助手带来了我以前的virtualenv,但是由于它们基于Leopard的Python 2.5,我认为我需要使用当前系统Python 2.7重新创建它们.

Migration Assistant brought over my previous virtualenvs, but since they were based on Leopard's Python 2.5, I figure I need to recreate each of them with the current system Python 2.7.

easy_install已经在PATH中了-可能是因为它与Lion的Python 2.7捆绑在一起;似乎不太可能是迁移助手的结果.我使用easy_install来安装virtualenv.

easy_install was already in the PATH -- probably because it was bundled with Lion's Python 2.7; it seems unlikely to be the result of Migration Assistant. I used easy_install to install virtualenv.

在我看来,这个问题与Xcode无关,也没有Xcode无关.这是由virtualenv命令放置在新虚拟环境中的文件中的特殊行:

This problem, it seems to me, doesn't have anything to do with Xcode or lack thereof. It's a peculiar line in a file placed in the new virtual env by the virtualenv command:


  File "/path/to/my/virtualenv/lib/python2.7/distutils/__init__.py", line 16, in 
    exec(open(os.path.join(distutils_path, '__init__.py')).read())
IOError: [Errno 2] No such file or directory: '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/__init__.py'

问题在于,在与Lion捆绑在一起的Python 2.7安装中,该库不包含.py源文件.该目录包含.pyc和.pyo文件,但不包含.py文件. virtualenv似乎并不期望如此.

The issue is that, in the Python 2.7 install bundled with Lion, the library doesn't come with .py source files. That directory contains .pyc and .pyo files, but no .py files. virtualenv doesn't seem to expect that.

我的解决方法是下载Python 2.7源:
http://python.org/ftp/python/2.7.2/Python- 2.7.2.tar.bz2

My workaround is to download Python 2.7 source:
http://python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2

并将distutils/__init__.py拆包到预期的位置:
sudo tar xvjf ~/Downloads/Python-2.7.2.tar.bz2 --strip-components=2 -C /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 Python-2.7.2/Lib/distutils/__init__.py

and unpack distutils/__init__.py into the expected place:
sudo tar xvjf ~/Downloads/Python-2.7.2.tar.bz2 --strip-components=2 -C /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 Python-2.7.2/Lib/distutils/__init__.py

这允许virtualenv成功完成,并且生成的Python解释器似乎正在运行.

That permits virtualenv to complete successfully, and the resulting Python interpreter seems to run.

鉴于Lion附带的Python 2.7库是不带源安装的,因此更改virtualenv尝试distutils/__init__.pydistutils/__init__.pyc似乎很有用?

Given that the Python 2.7 library bundled with Lion is installed without source, it might seem useful to change virtualenv to try for either distutils/__init__.py or distutils/__init__.pyc ?

这篇关于Python无法在Mac OSX上找到distutils_path的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆