Question

I am writing a script using python Spyder 2.2.5 with Windows 7, python 2.7

At the very beginning I have tried all the import ways:

from numpy import *

or

import numpy

and also

import numpy as np

And, for each an every line where I use numpy I am getting an error when compiling

QR10 = numpy.array(QR10,dtype=float)
QR20 = numpy.array(QR20,dtype=float)
QR11 = numpy.array(QR11,dtype=float)
QR21 = numpy.array(QR21,dtype=float)

enter image description here

However, even with this 30 errors, the script works if I run it....

Any help about this?

Was it helpful?

Solution

Python cannot actually be compiled. Spyder performs just a static code analysis using Pylint. Depending on the version of Pylint that is being used, it could be a bug or an undetectable case for it.

For example, the import statement (or the path that gets to it) could be within a conditional block, which cannot be resolved until runtime. Given that you are using Spyder, it could also be that you put your import statement directly on the console, or in a separate file, and then use the imported module from the script.

You may try to see if you receive the same error with a script like the following:

import numpy

QR10 = [1, 2, 3]
QR20 = [1, 2, 3]
QR11 = [1, 2, 3]
QR21 = [1, 2, 3]

QR10 = numpy.array(QR10,dtype=float)
QR20 = numpy.array(QR20,dtype=float)
QR11 = numpy.array(QR11,dtype=float)
QR21 = numpy.array(QR21,dtype=float)

You should not see the E0602 here. Funny enough, however, you may receive [E1101] Module 'numpy' has no 'array' member, because it turns out that numpy does some dynamic definition of members, so Pylint cannot know about it (as you may see here) of a bug that has actually been solved already.

The moral of the story is that Pylint errors shouldn't keep you awake at night. It's good to see the report, but if you are sure that your code makes sense and it runs just right, you may just ignore them - although trying to know why it is giving an error is always a good exercise.

OTHER TIPS

import numpy as np

then use

QR10 = np.array(QR10,dtype=float)  # instead of numpy.array
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top