Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Undefined variable from import" when importing numpy in eclipse pydev

I get "Undefined variable from import" error in Eclipse 3.7.2 PyDev 2.7.1 on Linux Mint Maya (Cinnamon) whenever I import a module from numpy. The problem only arises when importing numpy; other modules work just fine.

Info: numpy is compiled against the Intel MKL libraries. Python 2.7.3 [GCC 4.6.3]

example:

import numpy as np

a = np.array([1, 2])

Error message in PyDev editor: "Undefined variable from import: array"

I get similar errors for other numpy submodules.

The code runs properly either within Eclipse or in a terminal. The problem is only present in the Eclipse-PyDev editor.

like image 708
user1898037 Avatar asked Dec 12 '12 14:12

user1898037


2 Answers

The LD_LIBRARY_PATH has to contain paths to the MKL libraries. Even if LD_LIBRARY_PATH is set properly, it has to be explicitly specifed in Eclipse under Window > Preferences > Interpreter - Python, under the "Environment" tab on the right hand side. Add a new variable called "LD_LIBRARY_PATH" and paste the content of $LD_LIBRARY_PATH.

Once it is done, errors will only disappear from your code if a line is added to the code which uses a numpy object so that imports are checked again.

like image 179
user1898037 Avatar answered Sep 29 '22 12:09

user1898037


I managed to fix it by updating the Phyton interpreter in Eclipse. Just click on Apply button after successfully installed Numpy module.

like image 32
illaiza Avatar answered Sep 29 '22 13:09

illaiza