Pydev on Eclipse running wrong (deleted) file which shadowed numpy library

451 views Asked by At

I just committed a major noob blunder while playing around with basic functionalities of NumPy. I created a small file called "numpy.py" just so that play around with problems related to numpy. I could also later come back for reference - and the name would have helped. Obvious error :-

import numpy
  File "C:\Users\USERNAME\workspace\StackOverflow\python\numpy.py", line 25, in <module>
AttributeError: 'module' object has no attribute 'random'

I realized the problem - python was considering my current code as actual numpy and looking for random. I deleted that file and created a new one.

And the problem persists. This image explains it better than my words would. enter image description here

Now there's a completely new file with a different name - but still it's looking for some methods in the deleted file.

I've already tried:

  • Cleaning the Project
  • Restarting Eclipse
  • Run another .py (successfully) and then this one again
  • Removed all the conflicting files, created a totally new file. Still same. If the program contains import numpy, it would give same error.

I'd like to know (1) What actually happened wrong here? Why is eclipse so confused (2) How to resolve? (3) What are the best practices in such situations?

2

There are 2 answers

1
Aditya On BEST ANSWER

I'm the OP. Found a solution after a few minutes of posting this question.

Browsed to the folder containing the code. I noticed that there was a .pyc file for the numpy.pyc I had created earlier. Deleted that one and things are working file now.

enter image description here

However I'd still like to know how to avoid situations like this or resolve directly through eclipse. Though it works now!

0
smci On

This is called an orphaned .pyc file. Eclipse/PyDev now has a setting to automatically handle these (as of Oxygen / v4.7):

PyDev > Builders > "How to handle .pyc/$py.class deletion?" :
  Delete any orphaned .pyc file

Knowing Eclipse, presumably that action only gets triggered when you or it refreshes or restarts the workspace, or triggers a rebuild. There are some switches to try to make that automatic too. Or Eclipse > Restart if all else fails.