4

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
halfer
  • 19,824
  • 17
  • 99
  • 186
BoscoTsang
  • 394
  • 1
  • 14
  • Could you run `nm /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/Python | grep PyErr_ReplaceException`? – icktoofay Jun 29 '15 at 03:07
  • @icktoofay It comes out 0000000000092527 T __PyErr_ReplaceException – BoscoTsang Jun 29 '15 at 03:39
  • possible duplicate of [Python on my Mac is a mess, help me uninstall what I don't need](http://stackoverflow.com/questions/31887686/python-on-my-mac-is-a-mess-help-me-uninstall-what-i-dont-need) – kenorb Aug 08 '15 at 17:57

1 Answers1

0

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.

kenorb
  • 155,785
  • 88
  • 678
  • 743