Reputation: 65
I wanted to use Numba to run my python code on the GPU so I installed Anaconda, last version (4.6.12 with Python 3.7). I tried to load the function vectorize from numba:
from numba import vectorize
But I got the error code:
ImportError: cannot import name 'vectorize' from 'numba'
The module is installed, I don't get errors when I import it, but when I use the dir(numba)
command like so:
import numba
print(dir(numba))
I get this :
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'numba']
I tried to reinstall the module using the command conda install numba --force-reinstall
but I still get the error.
Upvotes: 2
Views: 211
Reputation: 152647
Pythons import
looks at different locations for matching modules. The (very simplified) order is (1) built-in C-modules (e.g. sys
) (2) current directory (3) built-in modules and installed packages 1.
What is relevant in your case is that Python found a numba
module (your numba.py
2) in the current directory it didn't look for an installed numba
module. So it should be sufficient to rename the numba.py
file to something else, e.g. my_numba.py
(and remove the corresponding file from the __pycache__
directory).
In general if you suspect that you imported the wrong module, you can always check the __file__
attribute (most modules have it) and check if it's the expected path:
import numba
print(numba.__file__)
1 It's actually a lot more complicated and one can also customize a lot of it, but that's actually not relevant here.
2 Yes, you can import the current module in itself - but it's generally not advised...
Upvotes: 1