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

12,472

Solution 1

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.

Solution 2

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

Solution 3

Are MKL libraries and numpy the same thing? @user1898039's answer didn't make sense to me (I'm not sure what path I should use for that property.

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

>>> import from numpy *

It was not. So, despite the fact that numpy was showing up in PyDev under the "Forced Builtins" tab in the Python Interpreter properties, it wasn't available to python from the command line and I imagine this caused the issue inside PyDev.

So, I fixed the problem by going to the numpy site and installing the newest version for windows. Technically I went to some other site that had a AMD64 version of the installer for windows, buy you know, same same. After that I tried to get the PYTHONPATH variable to recalculate all the libraries (this may have been unnecessary), but errors were still showing in the file on all the calls to array(). I did an autocomplete on the numpy package to get the list of functions, selected array() from that list, and all of the sudden all the errors cleared and everything is fine now.

Share:
12,472
user1898037
Author by

user1898037

Updated on July 20, 2022

Comments

  • user1898037
    user1898037 almost 2 years

    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.

  • BenB
    BenB over 10 years
    My problem: It worked fine in one session. After quitting and starting LiClipse again, I was getting this error. The second paragraph solved my problem. For me, the actions in the first were unnecessary (or maybe I did something like that when configuring LiClipse initially).
  • user1898037
    user1898037 over 9 years
    It seems there are quite a few components to make PyDev(Eclipse/Liclipse) recognize numpy. First, you have to check if numpy is installed properly as @ElDuderino suggested: >>> from numpy import * Then you have to "teach" pydev to prepare the environment for numpy. For me, it was the missing path to numpy files.
  • Dan H
    Dan H over 7 years
    Which OS/Eclipse version did this work for? Did not work for me. Could be an OS or Eclipse version thing. I'm running Windows 7 32-bit, with Eclipse 3.6.2. (Ancient, I know...)
  • David
    David about 3 years
    Then quit Eclipse and restart. Thanks.