0

I've been having troubles using numpy in python 2.7. I get the following error message:

import numpy

array = numpy.array([1,2,3])
print array

>>>array = numpy.array([1,2,3])
>>>AttributeError: 'module' object has no attribute 'array'

I've installed dozens of python packages in the past using the "pip install" command and never had any issues.

When installing numpy I went to my windows cmd and typed:

pip install numpy
>>>Installing collected packages: numpy
>>>Successfully installed numpy-1.15.4

To double check that it was installed successful and in the correct python folder I then typed the command a second time:

 pip install numpy
 >>>Requirement already satisfied: numpy in c:\python27\lib\site-packages (1.15.4)

This proved to me that numpy was installed in the correct python 2.7 path (and not in python 3.7 which I also have installed).

However, Im still getting the error message "module object has no attribute" whenever I try using numpy in python 2.7.

What am I doing wrong here?

Thanks

Melogs
  • 95
  • 6
  • Did you create a local file called `numpy.py` by any chance? – Andras Deak -- Слава Україні Dec 23 '18 at 19:46
  • 1
    You are absolutely spot on Andreas. I had called one of my test files nimpy.py. I changed it now to something else and it worked. Thats' Brilliant man. How did you figure this out so quickly? Thanks so much, Ive been tripping over this all morning today. Appreciate it the quick response! – Melogs Dec 23 '18 at 19:50
  • If numpy weren't installed you'd get an `ImportError`. Instead the import worked but the resulting object didn't have an `array` attribute. I.e. that numpy is not the numpy it should be. The most common problem in this scenario is what you have (shadowing of a module by a local file). – Andras Deak -- Слава Україні Dec 23 '18 at 19:53
  • 1
    Possible duplicate of [Importing installed package from script raises "AttributeError: module has no attribute" or "ImportError: cannot import name"](https://stackoverflow.com/questions/36250353/importing-installed-package-from-script-raises-attributeerror-module-has-no-at) – Antti Haapala -- Слава Україні Dec 23 '18 at 19:54

1 Answers1

1

As Andras Deak pointed out in the comments above: I had named one of my python files numpy.py and that was creating the conflict and resulting in the error message.

See Andras comments above for more detail.

Melogs
  • 95
  • 6