ImportError: : Symbol not found: __PyErr_ReplaceException

爷,独闯天下 提交于 2019-12-19 08:28:22

问题


I use homebrew install python 2.7.10 and usr/local/bin/python is linked to the python 2.7.10. But when I run my python code, an exception occurs as below. But when I use IPython import numpy it goes well.

When I use command which python it tells me that is /usr/local/bin/python while use whereis python it tells me that is /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:


Try downgrading your Python from 2.7.10 to 2.7.9, for example:

brew switch python 2.7.9

by overriding the existing one, as it seems there is some particular problem with 2.7.10.

For conda, try: conda install python=2.7.9 (as per this).

Also double check your PYTHONPATH variable if it's not overridden anywhere.

Alternatively consider using Python 3 instead.



来源:https://stackoverflow.com/questions/31106958/importerror-symbol-not-found-pyerr-replaceexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!