3
import numpy as np
arr = np.array([1, 2, 3, 4, 5])

print(arr)

print(type(arr))

AttributeError: partially initialized module 'numpy' has no attribute 'array' (most likely due to a circular import) I know this question has been asked before, but notice, import has been asked for correctly. What is a circular import?

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
Romanarmy
  • 31
  • 1
  • 1
  • 3
  • 9
    Is your file named `numpy.py`? If so, rename it. – SuperStormer Apr 23 '21 at 22:47
  • Sounds feasible. Had a similar problem with random. If this is the case, what was the answer to the numpy1 question that was posted previously? – Romanarmy Apr 23 '21 at 23:29
  • Does this answer your question? [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) – SuperStormer Jul 20 '22 at 06:08

4 Answers4

11

That is mostly because your python is confused so as to what numpy is being referred mostly because your file name could be numpy just change it.

2

I had your problem, this is a problem caused by your file naming. If you are doing your operations in the numpy file, you need to change this naming, for example, you can write numpyBasic.py instead of numpy.py

MrSpyX
  • 51
  • 2
0

In my case, the NumPy module is being imported indirectly by the Plotly library. I solved it by importing NumPy explicitly at the beginning of my code, before I import Plotly. This can help ensure that NumPy is fully initialized before it is used by Plotly and avoid circular import.

Hamzah
  • 8,175
  • 3
  • 19
  • 43
-1

Just for the name of the file, this error is generated. I have given the file name as "numpy.py" and I got the error. After that I have changed the file name as "n.py" and now it's working.so the solution is change the file name .

  • 1
    This has already been mentioned in the other answers. – Eric Aya Feb 11 '23 at 13:57
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/33827250) – handras Feb 18 '23 at 11:06