"Undefined variable from import" when importing numpy in eclipse pydev
Asked Answered
J

5

10

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.

Jordan answered 12/12, 2012 at 14:46 Comment(0)
J
3

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.

Jordan answered 29/12, 2012 at 13:47 Comment(2)
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).Dike
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.Jordan
E
2

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

Electrograph answered 2/11, 2016 at 8:27 Comment(2)
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...)Hooper
Then quit Eclipse and restart. Thanks.Howze
P
1

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.

Pappy answered 3/8, 2014 at 19:24 Comment(0)
F
0

I was able to resolve this by adding the following path to PYTHONPATH (Pydev => Python Interpreters => select an 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
Featherhead answered 11/5, 2015 at 16:19 Comment(0)
O
0

I occasionally see these errors for pandas objects, after re-starting Eclipse, even though I of course have 'import pandas as pd' at the top of my file.

I've discovered a simple workaround: I simply delete the import statement, save the file, paste it back in and re-save. The errors go away!

I'm on this version of Eclipse:

Eclipse for PHP Developers

Version: Mars.2 Release (4.5.2) Build id: 20160218-0600

Objective answered 10/2, 2021 at 17:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.