mitsuba-renderer / mitsuba-blender

Mitsuba integration add-on for Blender
BSD 3-Clause "New" or "Revised" License
267 stars 35 forks source link

Can't import mitsuba: ImportError: DLL load failed while importing mitsuba_ext: The specified procedure could not be found. #61

Closed EnigmaticCat123 closed 9 months ago

EnigmaticCat123 commented 1 year ago

Bug Description I'm using a custom build of mitsuba, following the instructions here.. After specifying the custom mitsuba path, I get the error "The 'mitsuba' native modules could not be imported.". Digging further, I tried importing mitsuba using blender's python exe, which worked without problems. However, when the trying to import mitsuba in blender's build-in console, i get the full error:

Traceback (most recent call last):
  File "C:\Users\user\Desktop\mitsubabuild\mitsuba3\build\Release\python\mitsuba\__init__.py", line 39, in <module>
    _import('mitsuba.mitsuba_ext')
  File "C:\Program Files\Blender Foundation\Blender 3.5\3.5\python\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 674, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 571, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1176, in create_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
ImportError: DLL load failed while importing mitsuba_ext: The specified procedure could not be found.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "C:\Users\user\Desktop\mitsubabuild\mitsuba3\build\Release\python\mitsuba\__init__.py", line 60, in <module>
    raise exc
ImportError: The 'mitsuba' native modules could not be imported. 

So blender obviously seems to find mitsuba_ext, as it gives a different error if I try to import a non-existing module with the same function. I've narrowed down that mitsuba_ext is "mitsuba_ext.cp310-win_amd64.pyd". Explicitly importing that specific file works without any problem using blender's python exe, but inside the blender terminal, i get the same "ImportError: The 'mitsuba' native modules could not be imported. ".

So it seems that the root cause is that somehow mitsuba_ext.cp310-win_amd64.pyd is imported differently inside of blender compared to blender's python exe run in cmd. If needed, I can send my build of mitsuba. Thanks for any help!

If this doesn't belong here, should I ask the blender or mitsuba guys for help?

Environment (please complete the following information):

bathal1 commented 1 year ago

Hi, Using a custom mitsuba build with blender is very brittle (particularly under windows), and I haven't had time to get to the bottom of this. Normally, compiling mitsuba with the same minor version of python as blender uses should be enough. The error you get is the one typically thrown because of such mismatches, but it seems you used the right version of python.

That said, unless you plan on modifying the addon yourself, using the pip-installed version of mitsuba should work more reliably (though there are also issues on Windows there...)

bathal1 commented 1 year ago

It seems that changes introduced in Blender 3.5 have broken the import of mitsuba from python's blender. Versions up to 3.4 work fine on my end, using both a custom build or the pip-installed version. I suggest you downgrade your version of blender while we investigate this issue. In order for blender to be able to load mitsube in these versions, you may need to launch it from a command prompt, with the --python-use-system-env flag.

shouhanzen commented 1 year ago

Hello, I am experiencing the same issue. When I was on version 3.5 I got the above error, in the same sequence as issue #57. After downgrading from Blender 3.5 to 3.4.1 though, I am still unable to install the plugin.

image

I am able to get the package to show in the package manager, but when I hit the checkbox, it lags for a couple seconds and then announces that it failed to load the package.

bathal1 commented 1 year ago

Did you launch blender using the --python-use-system-env flag ?

shouhanzen commented 1 year ago

Ah wonderful, launching blender with --python-use-system-env flag worked great on blender version 3.4.1 for me. Thanks for the help!

AbdolvakilFazli commented 1 year ago

launch blender using the --python-use-system-env flag

How to lunch blender using this --python-use-system-env flag? I'm using win 10

AbdolvakilFazli commented 1 year ago

okay , well thanks but how can I lunch blender using this --python-use-system-env flag? I'm using win 10

merlinND commented 1 year ago

@AbdolvakilFazli Here's a way to do it.

Open a command line prompt: press Windows + R, write cmd, press enter. In the terminal, paste:

"C:\Program Files\Blender Foundation\Blender 3.5\blender.exe" --python-use-system-env

and press enter. You might have to tweak depending on your install path.

AbdolvakilFazli commented 1 year ago

@merlinND @bathal1 Thank you very much. I had to downgrade to 3.4.1 too and now using your help everything is fine.

bathal1 commented 9 months ago

This should now be fixed with the latest release of the add-on. Please upgrade and re-open this issue if the problem persists.