Title: module 'numba.findlib' has no attribute 'get_lib_dir'
Tags: python;anaconda;numba
Question: I'm trying to learn how to use pyculib and got AttributeError: module 'numba.findlib' has no attribute 'get_lib_dir'
4 core CPU (intel) + GeForce GTX 745
File "", line 1, in
runfile('C:/Python/Scripts/LearnCUDA/curand.py', wdir='C:/Python/Scripts/LearnCUDA')
File "C:\Users\Administrator\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
execfile(filename, namespace)
File "C:\Users\Administrator\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Python/Scripts/LearnCUDA/curand.py", line 11, in
from pyculib import rand as curand
File "C:\Users\Administrator\Anaconda3\lib\site-packages\pyculib__init__.py", line 49, in
from . import blas, sparse, fft, rand, sorting
File "C:\Users\Administrator\Anaconda3\lib\site-packages\pyculib\sorting__init__.py", line 1, in
from .radixsort import RadixSort
File "C:\Users\Administrator\Anaconda3\lib\site-packages\pyculib\sorting\radixsort.py", line 38, in
lib = load_lib('radixsort')
File "C:\Users\Administrator\Anaconda3\lib\site-packages\pyculib\sorting\common.py", line 24, in load_lib
libpath = os.path.join(findlib.get_lib_dir(), fullname)
AttributeError: module 'numba.findlib' has no attribute 'get_lib_dir'
import numpy as np
from pyculib import rand as curand
prng = curand.PRNG(rndtype=curand.PRNG.XORWOW)
rand = np.empty(100000)
prng.uniform(rand)
print(rand[:10])
Comment: What is your version of cudatoolkit and cuda

Comment: Now I tried to reinstall them and got the following:

Comment: for cuda: PackagesNotFoundError: The following packages are not available from current channels: cuda

Comment: And for cudatoolkit: # All requested packages already installed.

Comment: after running numba -s I've got75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0 cudatoolkit   9.0 1 and cudnn 7.3.1  cuda9.0_0

Comment: Also just in case it would help  :W-10-10.0.17134-SP0  Python : MSC v.1900 64 bit (AMD64) Cpython 3.6.6 CUDA b'GeForce GTX 745' compute cap: 5 pci device id: 0 pci bus id: 1  CUDA driver : 7050  CUDA libraries: cublas, cusparse, cufft, curand, nvvm --- all open... ok

Comment: @Duck_dragon cudatoolkit 9.0 1 and cudnn 7.3.1 cuda9.0_0


Here is another answer: Navigate to C:\Users\Administrator\Anaconda3\lib\site-packages\pyculib\sorting\ and make a back up of common.py. Replace the code in common.py with
from numba import findlib
import ctypes
import os
import platform
import warnings
def library_extension():
p = platform.system()
if p == 'Linux':
return 'so'
if p == 'Windows':
return 'dll'
if p == 'Darwin':
return 'dylib'
def load_lib(libname):
fullname = 'pyculib_%s.%s' % (libname, library_extension())
devlib = os.path.join(os.path.abspath(os.path.dirname(__file__)), fullname)
if os.path.exists(devlib):
libpath = devlib
warnings.warn('Using in-tree library %s' % libpath)
else:
libpath = os.path.join(findlib.get_lib_dirs()[0], fullname)
return ctypes.CDLL(libpath)
If this dosent fix the problem revert to your backup
Comment for this answer: Thanks. I checked the common.py in my system and it differs from your code only in first line:  from __future__ import print_function, absolute_import, division
Comment for this answer: When I commented out the line, I've got the same: module 'numba.findlib' has no attribute 'get_lib_dir'
Comment for this answer: BTW, when I copy common.py into Spyder as findlib.py and run it doesn't complain. But when I commented out the 1-st line I've got: [autoreload of pyculib.sorting.common failed: Traceback (most recent call last):
File "C:\Users\Administrator\Anaconda3\lib\site-packages\IPython\extensions\autoreload.py", line 244, in check
superreload(m, reload, self.old_objects)
File "C:\Users\Administrator\Anaconda3\lib\site-packages\IPython\extensions\autoreload.py", line 378, in superreload
module = reload(module)
Comment for this answer: File "C:\Users\Administrator\Anaconda3\lib\imp.py", line 315, in reload
return importlib.reload(module)
File "C:\Users\Administrator\Anaconda3\lib\importlib\__init__.py", line 159, in reload
name=parent_name) from None
ImportError: parent 'pyculib.sorting' not in sys.modules
Comment for this answer: It was the line `libpath = os.path.join(findlib.get_lib_dir()[0], fullname)` that was wrong for me. `findlib.get_lig_dir()` does not exist. but `findlib.get_lib_dirs()` does but it returns a list. the `[0]` gets the string of the first item in that list. That's the only thing I changed on my end.

Here is another answer: The following steps solved the problem for me:
Download anaconda 3-5.1.0
Install numpy using conda install numpy=1.13.0
Install cudatoolkit 7.5 using conda install cudatoolkit=7.5
Install pyculib.
If it works then every thing is ok, if you have an error like CURAND_STATUS_LAUNCH_FAILURE when using Anaconda Accelerate on GTX 1060
you can then:
Install cudatoolkit=8.0 using conda install -c numba cudatoolkit=8.0

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 7, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:04/08/19', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><anaconda><numba>', 'Title': "module 'numba.findlib' has no attribute 'get_lib_dir'", 'ViewCount': 1545, 'id': 55579082, 'user_AboutMe': None, 'user_AccountId': 4353657.0, 'user_DisplayName': 'user3553069', 'user_Reputation': 11.0, 'user_Views': 12.0, 'user_id': 3553069.0}}