ImARandom
ImARandom

Reputation: 31

Jupyter notebook : Import error: DLL load failed (but works on .py) without Anaconda

I was trying to use CuPy inside a Jupyter Notebook on Windows10 and got this error :

---> from cupy_backends.cuda.libs import nvrtc
ImportError: DLL load failed while importing nvrtc: The specified procedure could not be found.

This is triggered by import cupy.

I know there is a bunch of threads about similar issues (DLLs not found by Jupyter under Windows), but everyone of them relies on conda, that I'm not using anymore.

I checked os.environ['CUDA_PATH'], which is set to C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.6 and is the right path.

Also, os.environ['PATH'] contains C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.6\\bin which is where the DLL is located.

I fixed it once by running pip install -U notebook, then it started failing again after restarting Jupyter. Running the same command (even with --force-reinstall) could not produce the same effect again.

I have no problems with CuPy when using a shell or a regular Python IDE. I could use workarounds like executing CuPy based commands outside Jupyter for myself, but that would go against using notebooks for pedagogy and examples, which is my major use of notebooks.

Would anyone have a fix for that not relying on conda ?

Upvotes: 1

Views: 277

Answers (1)

ImARandom
ImARandom

Reputation: 31

The error was showing up because I was importing PyTorch before CuPy.

Solution was to import cupy before torch.

Upvotes: 2

Related Questions