0

I'm trying to import numpy. I downloaded numpy compatible with python 2.7 (which is what is running on my mac 10.8). Before I did so, I created a python script called "numpy.py". Now, whenever I "import numpy" in a new script, it runs the script called "numpy.py" even after I have deleted that script. What do I do? How can I check to see if numpy was downloaded properly?

  • 4
    Do you still have a `numpy.pyc`? – jonrsharpe Jun 22 '15 at 21:27
  • Adding to jon's comment, .pyc files are usually hidden by default – Tim Jun 22 '15 at 21:32
  • The collections module lets you do `import collections` then `print collections.__file__` and it says which file it was loaded from. I don't know if numpy does, but it might be worth trying `print numpy.__file__` – TessellatingHeckler Jun 22 '15 at 21:32
  • @TessellatingHeckler that's Python generally, not `collections` specifically. – jonrsharpe Jun 22 '15 at 21:33
  • 3
    @saraccina then try deleting that, too! Python can still `import` from these bytecode-compiled files. – jonrsharpe Jun 22 '15 at 21:33
  • @jonrsharpe It doesn't work for `itertools` ... – TessellatingHeckler Jun 22 '15 at 21:34
  • 1
    @TessellatingHeckler that's because `itertools` is implemented in C (in CPython), not pure Python. It's therefore not imported from a Python file, so the `__file__` attribute isn't set. – jonrsharpe Jun 22 '15 at 21:34
  • @TimCastelijns Replying to "it works for one" and saying "that's Python generally" sounds like a claim that it will work for any module. If, in fact, it works for some and not others depending on some implementation details you don't know from merely using the module" we're no further forward than saying "try it with numpy it might work". – TessellatingHeckler Jun 22 '15 at 21:49
  • So delete anything python.pyc? – saraccina Jun 22 '15 at 21:51
  • yes, delete numpy.pyc. Other way (if the purpose is checking your numpy distribution) is to use an alias for a numpy module: `import numpy as np; a = np.version.version` – Ashalynd Jun 22 '15 at 22:26

0 Answers0