How to import Pyculib in Pycharm?

こ雲淡風輕ζ 提交于 2020-06-29 03:48:35

问题


I want to use pyculib.fft in a pycharm project, to be precise inside a numba.njit decorated function. Someone on Stackoverflow suggested to me to use it, since I need to find a way to use an fft function inside a numba.njit decorated function. But I can't get pyculib to work. I have tried using a Python 3.7 interpreter as well as an Anaconda interpreter. In both cases pyculib 1.0.1 is installed, which is the only version available in pycharm.

With Python interpreter:

import pyculib

Output:

C:\Users\Artur\Desktop\RL_framework\venv\Scripts\python.exe C:/Users/Artur/Desktop/RL_framework/help_functions/test3.py
Traceback (most recent call last):
  File "C:\Users\Artur\Desktop\RL_framework\venv\lib\site-packages\pyculib\utils\libutils.py", line 17, in __new__
    dll = open_cudalib(cls.lib)
  File "C:\Users\Artur\Desktop\RL_framework\venv\lib\site-packages\numba\cuda\cudadrv\libs.py", line 55, in open_cudalib
    path = get_cudalib(lib)
  File "C:\Users\Artur\Desktop\RL_framework\venv\lib\site-packages\numba\cuda\cudadrv\libs.py", line 48, in get_cudalib
    libdir = get_cuda_paths()['cudalib_dir'].info
  File "C:\Users\Artur\Desktop\RL_framework\venv\lib\site-packages\numba\cuda\cuda_paths.py", line 164, in get_cuda_paths
    'nvvm': _get_nvvm_path(),
  File "C:\Users\Artur\Desktop\RL_framework\venv\lib\site-packages\numba\cuda\cuda_paths.py", line 142, in _get_nvvm_path
    candidates = find_lib('nvvm', path)
  File "C:\Users\Artur\Desktop\RL_framework\venv\lib\site-packages\numba\misc\findlib.py", line 34, in find_lib
    return find_file(regex, libdir)
  File "C:\Users\Artur\Desktop\RL_framework\venv\lib\site-packages\numba\misc\findlib.py", line 46, in find_file
    entries = os.listdir(ldir)
FileNotFoundError: [WinError 3] Das System kann den angegebenen Pfad nicht finden: 'C:\\Users\\Artur\\Desktop\\RL_framework\\venv\\DLLs'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Artur/Desktop/RL_framework/help_functions/test3.py", line 1, in <module>
    import pyculib
  File "C:\Users\Artur\Desktop\RL_framework\venv\lib\site-packages\pyculib\__init__.py", line 49, in <module>
    from . import blas, sparse, fft, rand, sorting
  File "C:\Users\Artur\Desktop\RL_framework\venv\lib\site-packages\pyculib\sparse\__init__.py", line 2, in <module>
    from .api import *
  File "C:\Users\Artur\Desktop\RL_framework\venv\lib\site-packages\pyculib\sparse\api.py", line 6, in <module>
    from .binding import (cuSparse, CUSPARSE_INDEX_BASE_ZERO,
  File "C:\Users\Artur\Desktop\RL_framework\venv\lib\site-packages\pyculib\sparse\binding.py", line 1307, in <module>
    cuSparse = _init_cuSparse()
  File "C:\Users\Artur\Desktop\RL_framework\venv\lib\site-packages\pyculib\sparse\binding.py", line 1292, in _init_cuSparse
    name, func = _init_api_function(k, v)
  File "C:\Users\Artur\Desktop\RL_framework\venv\lib\site-packages\pyculib\sparse\binding.py", line 1237, in _init_api_function
    lib = libcusparse()
  File "C:\Users\Artur\Desktop\RL_framework\venv\lib\site-packages\pyculib\utils\libutils.py", line 20, in __new__
    e))
Exception: Cannot open library for cusparse:
[WinError 3] Das System kann den angegebenen Pfad nicht finden: 'C:\\Users\\Artur\\Desktop\\RL_framework\\venv\\DLLs'

Process finished with exit code 1

Das System kann den angegebenen Pfad nicht finden means system can not find stated path

With Anaconda interpreter:

import pyculib

Output:

C:\Users\Artur\Anaconda\python.exe C:/Users/Artur/Desktop/RL_framework/help_functions/test3.py
Traceback (most recent call last):
  File "C:\Users\Artur\Anaconda\lib\site-packages\pyculib\utils\libutils.py", line 17, in __new__
    dll = open_cudalib(cls.lib)
  File "C:\Users\Artur\Anaconda\lib\site-packages\numba\cuda\cudadrv\libs.py", line 56, in open_cudalib
    return ctypes.CDLL(path)
  File "C:\Users\Artur\Anaconda\lib\ctypes\__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] Das angegebene Modul wurde nicht gefunden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Artur/Desktop/RL_framework/help_functions/test3.py", line 1, in <module>
    import pyculib
  File "C:\Users\Artur\Anaconda\lib\site-packages\pyculib\__init__.py", line 49, in <module>
    from . import blas, sparse, fft, rand, sorting
  File "C:\Users\Artur\Anaconda\lib\site-packages\pyculib\sparse\__init__.py", line 2, in <module>
    from .api import *
  File "C:\Users\Artur\Anaconda\lib\site-packages\pyculib\sparse\api.py", line 6, in <module>
    from .binding import (cuSparse, CUSPARSE_INDEX_BASE_ZERO,
  File "C:\Users\Artur\Anaconda\lib\site-packages\pyculib\sparse\binding.py", line 1307, in <module>
    cuSparse = _init_cuSparse()
  File "C:\Users\Artur\Anaconda\lib\site-packages\pyculib\sparse\binding.py", line 1292, in _init_cuSparse
    name, func = _init_api_function(k, v)
  File "C:\Users\Artur\Anaconda\lib\site-packages\pyculib\sparse\binding.py", line 1237, in _init_api_function
    lib = libcusparse()
  File "C:\Users\Artur\Anaconda\lib\site-packages\pyculib\utils\libutils.py", line 20, in __new__
    e))
Exception: Cannot open library for cusparse:
[WinError 126] Das angegebene Modul wurde nicht gefunden

Process finished with exit code 1

Das angegebene Modul wurde nicht gefunden means the stated module can not be found

Thank you for your time.

Edit:

Following @norok2's advice I've tried running import pyculib on a linux server with an anaconda3 interpreter. It has numba and cudatoolkit installed and 3 compatible GPUs ( 2 x Quadro P2000 and 1 x RTX 2080).

Running the import command throws this error:

/home/amu/anaconda3/bin/python /home/amu/Desktop/RL_framework/help_functions/test.py
Traceback (most recent call last):
  File "/home/amu/Desktop/RL_framework/help_functions/test.py", line 1, in <module>
    import pyculib
  File "/home/amu/anaconda3/lib/python3.7/site-packages/pyculib/__init__.py", line 49, in <module>
    from . import blas, sparse, fft, rand, sorting
  File "/home/amu/anaconda3/lib/python3.7/site-packages/pyculib/sparse/__init__.py", line 2, in <module>
    from .api import *
  File "/home/amu/anaconda3/lib/python3.7/site-packages/pyculib/sparse/api.py", line 6, in <module>
    from .binding import (cuSparse, CUSPARSE_INDEX_BASE_ZERO,
  File "/home/amu/anaconda3/lib/python3.7/site-packages/pyculib/sparse/binding.py", line 1307, in <module>
    cuSparse = _init_cuSparse()
  File "/home/amu/anaconda3/lib/python3.7/site-packages/pyculib/sparse/binding.py", line 1292, in _init_cuSparse
    name, func = _init_api_function(k, v)
  File "/home/amu/anaconda3/lib/python3.7/site-packages/pyculib/sparse/binding.py", line 1237, in _init_api_function
    lib = libcusparse()
  File "/home/amu/anaconda3/lib/python3.7/site-packages/pyculib/utils/libutils.py", line 25, in __new__
    inst._initialize()
  File "/home/amu/anaconda3/lib/python3.7/site-packages/pyculib/utils/libutils.py", line 34, in _initialize
    fn = getattr(self.dll, name)
  File "/home/amu/anaconda3/lib/python3.7/ctypes/__init__.py", line 369, in __getattr__
    func = self.__getitem__(name)
  File "/home/amu/anaconda3/lib/python3.7/ctypes/__init__.py", line 374, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: /home/amu/anaconda3/lib/libcusparse.so.10.3.1.89: undefined symbol: cusparseCaxpyi_v2

Process finished with exit code 1

Edit_2:

Downgrading cudatoolkit to version 10.1.168 and below produces following Error. pyculib is only avaliable in version 1.0.1 in pycharm:

/home/amu/anaconda3/bin/python /home/amu/Desktop/RL_framework/help_functions/test.py
Traceback (most recent call last):
  File "/home/amu/Desktop/RL_framework/help_functions/test.py", line 1, in <module>
    import pyculib
  File "/home/amu/anaconda3/lib/python3.7/site-packages/pyculib/__init__.py", line 49, in <module>
    from . import blas, sparse, fft, rand, sorting
  File "/home/amu/anaconda3/lib/python3.7/site-packages/pyculib/sorting/__init__.py", line 1, in <module>
    from .radixsort import RadixSort
  File "/home/amu/anaconda3/lib/python3.7/site-packages/pyculib/sorting/radixsort.py", line 30, in <module>
    from .common import load_lib
  File "/home/amu/anaconda3/lib/python3.7/site-packages/pyculib/sorting/common.py", line 2, in <module>
    from numba import findlib
ImportError: cannot import name 'findlib' from 'numba' (/home/amu/anaconda3/lib/python3.7/site-packages/numba/__init__.py)

Process finished with exit code 1

来源:https://stackoverflow.com/questions/62360236/how-to-import-pyculib-in-pycharm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!