Bilal
Bilal

Reputation: 3855

AttributeError: module 'cupy' has no attribute 'array'

I have just installed cupy v-6 on Win-10 using conda conda install -c anaconda cupy and the installation was going smoothly, my cuda version is 10.1, Python 3.7.4,

when I ran the following code, I get the error: AttributeError: module 'cupy' has no attribute 'array'

print dir result:

['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'cp', 'np']

Edit:

Full Error

Traceback (most recent call last):
  File "D:\code\cupy.py", line 2, in <module>
    import cupy as cp
  File "D:\code\cupy.py", line 4, in <module>
    x_gpu = cp.array([1, 2, 3])
AttributeError: module 'cupy' has no attribute 'array'`
The code:

My code

import numpy as np
import cupy as cp

x_gpu = cp.array([1, 2, 3])

Upvotes: 2

Views: 8133

Answers (1)

Kalana
Kalana

Reputation: 6143

Your file name shouldn't be the same name as cupy. Therefore rename your file name and run again the code.

because, when you try to import cupy, it calls your cupy.py file instead of your cupy library. That's the reason your code didn't work

Upvotes: 5

Related Questions