Skip to content

Can't import mitsuba in a conda environment with openexr installed [🐛 bug report] #411

@Microno95

Description

@Microno95

Summary

Unable to import mitsuba in a conda environment on windows if the environment has openexr and openexr-python installed as mitsuba cannot find its own openexr libraries.

System configuration

  • Platform: Windows
  • Compiler: MSVC 2019 (Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29337 for x64)
  • Python version: 3.8.5
  • Mitsuba 2 version: 2.2.1
  • Compiled variants:
    • scalar_rgb
    • scalar_mono
    • scalar_spectral

Description

When importing Mitsuba 2 in a conda environment on Windows where openexr and openexr-python (python bindings for OpenEXR) are installed from the conda repositories, the mitsuba modules do not correctly load due to the .dll search path prioritising the environment openexr libraries over the mitsuba compiled ones. For example, Half.dll in the environment is found before the Half.dll library in dist/. You can check this by running:

>>> import ctypes
>>> import ctypes.util
>>> print(ctypes.util.find_library('Half.dll'))
C:\Users\ekin4\.conda\envs\test_exr_mitsuba\Library\bin\Half.dll

I've tested this on a Linux conda environment where the issue does not occur so this is entirely a problem with how Windows handles loading of .dll files and where it searches for them.

Steps to reproduce

In a shell with conda installed

  1. conda create -n test_exr_mitsuba python=3.8 numpy scipy openexr openexr-python -c conda-forge
  2. python -m mitsuba (alternatively run python and call import mitsuba)
  3. The above should raise an error with the cause:
Traceback (most recent call last):
  File "G:\research_files\academic_work\git_repositories\mitsuba_renderer_folder\mitsuba2\build_windows\release\dist\python\mitsuba\__init__.py", line 16, in <module>
    _import('mitsuba.core_ext')
  File "C:\Users\ekin4\.conda\envs\test_exr_mitsuba\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 556, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1101, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed while importing core_ext: The specified procedure could not be found.```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions