Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numpy fails with python-dbg (undefined symbol: Py_InitModule4_64)

Using Python 2.7.3 with Numpy 1.6.2 on a 64-bit Ubuntu 12.04. Additional versions are present on the system (Python 2.6.4 and Numpy 1.6.1) but to the best of my knowledge these have no influence on the events described below.

I'm working on a Python program which uses Numpy, and getting an error when I try to run a certain command from the program. So, I decided to install python2.7-dbg to run the program with it and see if that can help with debugging. So I run

$ python-dbg <command>

instead of

$ python <command>

However, this gives an "undefined symbol: Py_InitModule4_64" error related to numpy. It doesn't matter what exactly I try to run; the error also occurs for commands that succeed if run with the "regular" python. It occurs even if I try to import numpy into a blank python-dbg prompt:

$ python-dbg
Python 2.7.3 (default, Aug  1 2012, 04:55:00)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in <module>
    import add_newdocs
  File "/usr/local/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in <module>
    from numpy.lib import add_newdoc
  File "/usr/local/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 4, in <module>
    from type_check import *
  File "/usr/local/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 8, in <module>
    import numpy.core.numeric as _nx
  File "/usr/local/lib/python2.7/dist-packages/numpy/core/__init__.py", line 5, in <module>
    import multiarray
ImportError: /usr/local/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: Py_InitModule4_64
[134187 refs]
>>>

Importing numpy succeeds when in a pure python prompt.

I've had no luck finding information on the internet. The closest match to my error is this bug on debian which is the exact same situation but has been closed before any further information was provided. I've installed both the python-numpy-dbg and the python-apt-dbg packages from APT; I have sudo access to the machine so the changes I make are valid system-wide. As far as I know, no chroot options have been set for any of the processes I'm trying to run, so the Debian bug page is of no help to me.

Any assistance will be greatly appreciated.

like image 633
Boris Avatar asked Nov 27 '12 15:11

Boris


1 Answers

As confirmed by the OP, the clue here is in the traceback which shows that numpy you're importing is in /usr/local/lib/. However, packages installed by apt go into /usr/lib/pythonX.Y, where as non-Ubuntu Python packages installed with pip, easy_install, etc. are installed under /usr/local/lib/pythonX.Y and supersedes the system packages.

For now you should uninstall the Numpy you have installed under /usr/local/lib/python2.7/dist-packages in order for the one installed by python-numpy to work. In the future you might be able to have both installed and do something with usercustomize.py to switch between them, but I'm not on an Ubuntu machine right now so I have no way of testing that out.

like image 133
Iguananaut Avatar answered Sep 29 '22 07:09

Iguananaut