Romanarmy
Romanarmy

Reputation: 51

AttributeError: partially initialized module 'numpy' has no attribute 'array' (most likely due to a circular import)

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?

Upvotes: 5

Views: 28030

Answers (4)

Hamzah Al-Qadasi
Hamzah Al-Qadasi

Reputation: 9786

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.

Upvotes: 0

user21193253
user21193253

Reputation: 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 .

Upvotes: -1

MrSpyX
MrSpyX

Reputation: 71

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

Upvotes: 3

Paritosh Wankhade
Paritosh Wankhade

Reputation: 181

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.

Upvotes: 18

Related Questions