ImportError DLL while running PyOptiX hello.py example on Windows

Hi,

I would like to install pyoptix on Windows 10, I cloned the otk_pyoptix repo and followed the installation guide on Windows CMD terminal:

I created a conda environment:
conda create -n pyoptix-windows python numpy conda-forge::cupy pillow pytest

Activated it:
conda activate pyoptix-windows

Installed pynvrtc:
pip install pynvrtc

Set the PYOPTIX_CMAKE_ARGS environment variable:
set "PYOPTIX_CMAKE_ARGS=-DOptiX_INSTALL_DIR=C:\ProgramData\NVIDIA Corporation\OptiX SDK 8.0.0" (I just added quotes to deal with spaces)

I then went in optix\ folder and installed the package using:
pip install . (because python setup.py install is deprecated.)
Which succesfully installed the package in both cases.

Then when I want to run hello.py using python hello.py, I have the following error message:

Traceback (most recent call last):
  File "H:\otk-pyoptix\examples\hello.py", line 8, in <module>
    import optix
ImportError: DLL load failed while importing optix: The specified module could not be found.

To be sure that it’s not coming from right permissions, I tried to copy the OptiX SDK 8.0.0\ folder in in my C:\Temp\ folder, update the PYOPTIX_CMAKE_ARGS variable and reinstalled pyoptix, but it does not changed anything.

I am already using pyoptix with OptiX 8.0.0 on Linux and it works well, so I supposed it doesn’t come from the OptiX version.

I also tried using python setup.py install instead but it does not change anything.
I even tried to create an optix path without spaces but same problem.
And echo %PYOPTIX_CMAKE_ARGS% is printing well the optix path, with or without spaces.

I don’t know what I could miss from the guide,
thank you in advance for your help.

So it seems to load a pyd file named optix.cp312-win_amd64.pyd.
If I put import optix.cp39_win_amd64 instead of import optix I got the same message.

But with all other import names like for example import optix.cp39_win_amd64_000, it gives the error ModuleNotFoundError: No module named 'optix.cp39_win_amd64_000'.
So specifically the pyd file optix.cp312-win_amd64.pyd seems to be somewhat read but cannot be loaded for an unknown reason.

On linux, this file equivalent is optix.cpython-39-x86_64-linux-gnu.so.

As you have discovered, the issue is with python finding and loading the optix module. It looks like the module is being built, which means PYOPTIX_CMAKE_ARGSis working fine. The question is why python isnt loading the module. Are you using a 64b build of windows and python?

Hi,

Thank you for responding, I am indeed on a 64-bits Windows 10.
I printed the sys.maxsize value in hello.py to be sure, and I also run python in 64-bits.

I have a current config with 3 graphic devices:

  • Citrix indirect Display Adapter
  • an Intel Iris Xe Graphics
  • an NVIDIA RTX A500 Laptop GPU, with driver version 551.78

I wish I had more informations to give about the ImportError but I don’t know how to have much deeper infos.


In parallel, I tried to install pyoptix on 3 friends’ and colleagues’ PC with NVIDIA Graphic card and 64-bits Windows 10 to check if the same error appears but, on their side, they are all stuck during the pip install step with a CMake error:

-- Building for: NMake Makefiles
      CMake Error at CMakeLists.txt:6 (project):
        Generator
          NMake Makefiles
        does not support platform specification, but platform
          x64
        was specified.

By commenting the lines 53-54 of the setup.py of optix folder to remove the architecture specification cmake_args += ['-A', 'x64'], another file not found error appears:

-- Building for: NMake Makefiles
      CMake Error at CMakeLists.txt:6 (project):
        Running
         'nmake' '-?'
        failed with:
         The specified file was not found

It seems to come from the build folder extdir that is deleted on their side and that is not delete on my side. With all 4 using the last stable CMake version 3.23.2.

Thank you for your help.

[EDIT] I finally solved the x64 platform specification issue on my friend’ PC, it was because I forgot to install the C++ development suite of Visual Studio, so we didn’t had the C/C++ compilers for Windows.
But the same error appeared then during the hello.py execution. His graphic card is an NVIDIA GeForce GTX 1060 3GB, and he also have a Windows 10 64-bits and a 64-bits Python interpreter.

The
Generator NMake Makefiles does not support platform specification, but platform x64 was specified.
error seems to be common. Searching a bit on the web shows that this is usually a case of dlib not being installed on the system. Can you try: pip install dlib?

Hi Keith,

So, after several days of research, I finally found out a first temporary solution of the problem:

By loading manually the cudart DLL before import optix using ctypes.CDLL:

import ctypes
ctypes.CDLL("C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.4/bin/cudart64_12.dll")
import optix

and by replacing nvrtc_dll = os.environ.get('NVRTC_DLL') by our own nvrtc DLL path nvrtc_dll = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.4/bin/nvrtc64_120_0.dll"

hello.py achieves to run.


To be fair, I don’t exactly understand why by loading manually cudart64_12.dll before, it solves the importing of optix.

(All the more, all dependency walkers as well as dlltracer does not show problems concerning the loading of cudart64_12.dll. They instead points out msvcp140.dll and vcruntime140_1.dll that are Windows System32 DLL. But those seems to be a red herring after verifying the files system integrity and reinstalling all the Microsoft Visual C++ Redistributable versions possible without any change seen.)

Otherwise, concerning the NVRTC DLL, if we do not specify the NVRTC DLL path explicitly and leave the nvrtc_dll variable, it crash with the following error:

FileNotFoundError: Could not find module 'nvrtc64_92.dll' (or one of its dependencies). Try using the full path with constructor syntax.

Because there is no version 92, there is only the version 120. The NVRTC version is not matching with the version available in:
C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.4/bin/

In parallel, I tested on 3 other Windows 10 PC with NVidia GC to be sure, and the same problem seems to appear each time.

I didn’t had the time to see how we could solve this properly without having to add manual DLL before importing, and the NVRTC DLL file path. I will try to see how to do.

Thank you for your help and consideration.


Concerning the CMake x64 specification error, it is appearing when the C++ development suite of Visual Studio is not installed. So it is solvable by installing “Desktop Development C++” in the Visual Studio Installer. I edited my last-post few days ago to write down the solution I found for this.

Hi,

A cleaner solution to solve the issue that worked for me:

  • set the NVRTC_DLL environment variable to your own nvrtc DLL path
    (in my case set NVRTC_DLL=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4\bin\nvrtc64_120_0.dll);

  • add the cuda binary path to the DLL directories os.add_dll_directory(os.environ.get('CUDA_PATH') + "/bin") before import optix.

Then, pyoptix examples are able to run on Windows.

I didn’t found a way to change the optix package so that it can take into account the cuda binary directory internally…

Btw, thank you for creating pyoptix, this is a really usefull tool that helps me a lot.

Hope this helps.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.