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

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

Info: numpy compiled against 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 numerical submodules.

The code works correctly either inside Eclipse or in the terminal. The problem is present only in the Eclipse-PyDev editor.

+7
eclipse import numpy environment-variables pydev
source share
4 answers

LD_LIBRARY_PATH must contain the paths to the MKL libraries. Even if the LD_LIBRARY_PATH parameter is set correctly, it must be explicitly specified in Eclipse under "Window"> "Preferences"> "Interpreter - Python" on the "Environment" tab on the right. Add the new variable "LD_LIBRARY_PATH" and insert the contents of $LD_LIBRARY_PATH .

Once this is done, errors will only disappear from your code if the line is added to the code that uses the numpy object so that the import is checked again.

+2
source share

Are MKL and numpy libraries the same? @ user1898039 the answer did not make sense to me (I'm not sure which way I should use for this property.

I found another way to fix this problem - I checked the python command line to see if numpy is installed there by calling:

>>> import from numpy *

This is not true. Thus, even though numpy appeared in PyDev under the "Forced Built-in Functions" tab in the Python Interpreter properties, it was not accessible to python from the command line, and I think this caused a problem inside PyDev.

So, I fixed the problem by going to the numpy site and installing the latest version for Windows. Technically, I went to some other site on which the version of the AMD64 installer for Windows was installed, buy, you know, the same thing. After that, I tried to list the PYTHONPATH variable to recount all the libraries (this may have been superfluous), but errors still showed up in the file in all calls to array (). I did autocomplete in the numpy package to get a list of functions, the selected array () from this list, and all the sudden errors were removed, and now everything is fine.

+1
source share

I managed to solve this problem by adding the following path to PYTHONPATH (Pydev => Python Interpreters => select Interpreter libraries =>):

 /usr/local/anaconda/lib/python2.7/lib/lib-dynload 

installed packages (among others):

 conda==3.10.1 numpy==1.9.2 scipy==0.15.1 
0
source share

I managed to fix this by updating the Phyton interpreter in Eclipse. Just click the "Apply" button after successfully installing the Numpy module.

0
source share

All Articles