IfcOpenShell / IfcOpenShell

Open source IFC library and geometry engine
GNU Lesser General Public License v3.0
1.8k stars 715 forks source link

Geom occ_utils imports V3d, AIS, Graphic3d, which are missing DLLs in Conda OCE #812

Closed Moult closed 3 years ago

Moult commented 4 years ago

The latest IfcOpenBot build e44221c has a little thing that breaks the BlenderBIM Add-on out of the box. This is the relevant history #736 and the PR that caused breakage This is the error:

Modules Installed (blenderbim) from 'C:\\Users\\moud308\\Downloads\\blender28-bim-200318-win.zip' into 'C:\\Users\\moud308\\AppData\\Roaming\\Blender Foundation\\Blender\\2.81\\scripts\\addons'
Traceback (most recent call last):
  File "C:\Users\moud308\AppData\Roaming\Blender Foundation\Blender\2.81\scripts\addons\ifcopenshell\geom\occ_utils.py", line 31, in <module>
    from OCC.Core import V3d, TopoDS, gp, AIS, Quantity, BRepTools, Graphic3d
ModuleNotFoundError: No module named 'OCC.Core'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender 2.81\2.81\scripts\modules\addon_utils.py", line 351, in enable
    mod = __import__(module_name)
  File "C:\Users\moud308\AppData\Roaming\Blender Foundation\Blender\2.81\scripts\addons\blenderbim\__init__.py", line 31, in <module>
    from . import ui, prop, operator
  File "C:\Users\moud308\AppData\Roaming\Blender Foundation\Blender\2.81\scripts\addons\blenderbim\operator.py", line 8, in <module>
    from . import import_ifc
  File "C:\Users\moud308\AppData\Roaming\Blender Foundation\Blender\2.81\scripts\addons\blenderbim\import_ifc.py", line 2, in <module>
    import ifcopenshell.geom
  File "C:\Users\moud308\AppData\Roaming\Blender Foundation\Blender\2.81\scripts\addons\ifcopenshell\geom\__init__.py", line 43, in <module>
    from . import occ_utils as utils
  File "C:\Users\moud308\AppData\Roaming\Blender Foundation\Blender\2.81\scripts\addons\ifcopenshell\geom\occ_utils.py", line 33, in <module>
    from OCC import V3d, TopoDS, gp, AIS, Quantity, BRepTools, Graphic3d
  File "C:\Users\moud308\AppData\Roaming\Blender Foundation\Blender\2.81\scripts\addons\OCC\V3d.py", line 13, in <module>
    from . import _V3d
ImportError: DLL load failed: The specified module could not be found.

This is caused by geom/occ_utils.py L30:

try:
    from OCC.Core import V3d, TopoDS, gp, AIS, Quantity, BRepTools, Graphic3d
except ImportError:
    from OCC import V3d, TopoDS, gp, AIS, Quantity, BRepTools, Graphic3d

For some reason, the OCE builds I grab from Anaconda do not seem to contain the DLLs required on Windows (haven't tested Linux and MacOS) for the V3d module, AIS module, and Graphic3d module. For completeness, here are the builds I'm grabbing:

PYTHONOCC_URL:=https://anaconda.org/DLR-SC/pythonocc-core/0.17.3/download/win-64/pythonocc-core-0.17.3-py37he980bc4_10.tar.bz2
OCE_URL:=https://anaconda.org/DLR-SC/oce/0.17.2/download/win-64/oce-0.17.2-he980bc4_14.tar.bz2
TBB_URL:=https://anaconda.org/DLR-SC/tbb/2019.5/download/win-64/tbb-2019.5-he980bc4_0.tar.bz2

This error did not occur on previous builds, since previously those modules were lazy-loaded in their respective functions. E.g.:

def initialize_display():
    import OCC.V3d
    [ ... snip ... ]

A workaround for me is to patch the file to make it lazy-load the modules again (after all, I don't actually use the initialize_display etc functions). A better solution would be to find where those DLLs are ... but perhaps I'm just out of luck and Conda doesn't have them.

Thoughts?

aothms commented 4 years ago

Hm, so it's not about the .Core. part, it's just about making the modules now import at the beginning and somehow when you have downloaded the modules manually the runtime linker cannot find them?

I think it'd be good if you can check if you can reproduce this behaviour in a miniconda environment with dependencies properly installed through conda to see if it's related to the manual download or related to incompatibility between older oce packages and ifcopenshell.

Alternatively perhaps investigate if the latest builds from conda-forge work better. https://anaconda.org/conda-forge/pythonocc-core/files

Edit: one more thing, keep in mind that there are three layers of modules. The V3d.py generated by swig. The _V3d.pyd imported by the .py. And the TKV3d.dll from oce. The error seems to be related to the second item, which is still pythonocc-core and not oce.

Edit2: So that's ./Lib/site-packages/OCC/_V3d.pyd in the pythonocc-core archive

Moult commented 3 years ago

Closing as no longer relevant :)

Andrej730 commented 2 months ago

Removing https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/blenderbim/occ_utils.py: