ImportError ::找不到符号:__PyErr_ReplaceException

时间:2015-06-29 02:34:07

标签: python numpy homebrew

我使用homebrew install python 2.7.10并且usr/local/bin/python链接到python 2.7.10。但是当我运行我的python代码时,会发生如下异常。但是当我使用IPython导入numpy时它很顺利。

当我使用python它告诉我/usr/local/bin/python的命令时,使用whereis是python它告诉我那是/usr/bin/python

Traceback (most recent call last):
  File "main.py", line 9, in <module>
    import numpy
  File "/usr/local/lib/python2.7/site-packages/numpy/__init__.py", line 170, in <module>
    from . import add_newdocs
  File "/usr/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/usr/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 46, in <module>
    from numpy.testing import Tester
  File "/usr/local/lib/python2.7/site-packages/numpy/testing/__init__.py", line 13, in <module>
    from .utils import *
  File "/usr/local/lib/python2.7/site-packages/numpy/testing/utils.py", line 15, in <module>
    from tempfile import mkdtemp
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyErr_ReplaceException
  Referenced from: /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
  Expected in: flat namespace
 in /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so

1 个答案:

答案 0 :(得分:0)

尝试将Python从2.7.10降级到2.7.9,例如:

brew switch python 2.7.9

通过覆盖现有的,因为2.7.10似乎存在一些特殊问题。

对于conda,请尝试:conda install python=2.7.9(根据this)。

如果PYTHONPATH变量未在任何地方被覆盖,请仔细检查。

或者考虑使用Python 3。