ImportError:无法导入名称'compile'

时间:2016-01-28 21:49:45

标签: python macos tensorflow

我正在尝试在我的Mac上安装python 3.4和TensorFlow(OSX El Capitan版本10.11.1)。
我按照这里的说明进行操作

Pip Installation

我能做到

$ sudo easy_install pip
$ sudo easy_install --upgrade six  

然后这部分变得困难:

$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl  

我输入了密码; 它给了我一个追溯:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2859, in _dep_map
return self.__dep_map
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2696, in __getattr__
raise AttributeError(attr)
AttributeError: _DistInfoDistribution__dep_map

在处理上述异常期间,发生了另一个异常:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources/__init__.py", line 3138, in <module>
@_call_aside
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources/__init__.py", line 3124, in _call_aside
f(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources/__init__.py", line 3151, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources/__init__.py", line 661, in _build_master
ws.require(__requires__)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources/__init__.py", line 962, in require
needed = self.resolve(parse_requirements(requirements))
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources/__init__.py", line 857, in resolve
new_requirements = dist.requires(req.extras)[::-1]
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2640, in requires
dm = self._dep_map
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2861, in _dep_map
self.__dep_map = self._compute_dependencies()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2878, in _compute_dependencies
from _markerlib import compile as compile_marker
ImportError: cannot import name 'compile'

我是否遗漏了任何重要信息?

1 个答案:

答案 0 :(得分:1)

此错误的主要原因是您尝试安装的软件包是 Python 2 轮文件。 (URL中的py2是这方面的线索此外,正如Guy Coder在评论中指出的那样,你正在安装TensorFlow的0.5.0版本,它不支持Python 3。)

最好的解决方案是安装Python 3–compatible package

$ sudo pip install --upgrade http://storage.googleapis.com/tensorflow/mac/tensorflow-0.6.0-py3-none-any.whl

(看来这些链接在网站上很容易找到,所以我们很快就会解决这个问题。)