RhinoCode ScripEditor for development of libraries

@Petras_Vestartas Ok I got it to work but the solution is quite complicated:

Important Notes:

  1. compas_wood depends on wood_pybind11.cp39-win_amd64.pyd that has its own list of dependencies.

The command dumpbin /dependents C:\Users\ein\compas_wood\src\wood_pybind11.cp39-win_amd64.pyd provides a list of dlls that the .pyd depends on. We need to make sure python can find these dlls.

File Type: DLL
  Image has the following dependencies:
    liblapack.dll
    libblas.dll
    python39.dll
    libcblas.dll
    KERNEL32.dll
    VCRUNTIME140.dll
    api-ms-win-crt-stdio-l1-1-0.dll
    api-ms-win-crt-heap-l1-1-0.dll
    api-ms-win-crt-runtime-l1-1-0.dll
    api-ms-win-crt-string-l1-1-0.dll
  1. .pyd is compiled against your conda env python which means that python.exe can easily find these aforementioned dlls.

  2. The compas_wood packages is also installed there which means Libs/site-packages/easy-install.pth file points the python runtime to where compas_wood modules is located.

Now to get the python in Rhino to load the package installed in a conda environment, we need to:

#! python 3

import os
import os.path as op
import sys
import ctypes

CONDA_ENV = r'C:\Users\ein\.conda\envs\wood-dev'
COMPAS_WOOD_PATH = r'C:\Users\ein\compas_wood\src'

# add the paths of site-packages in conda environment so other packages that compas_wood
# depend on can be found e.g. compas
sys.path.append(op.join(CONDA_ENV, r"Lib\site-packages"))

# add the location of compas_wood source so we can import this
sys.path.append(COMPAS_WOOD_PATH)

# tell python where it can find dlls. this is required to find all other .dll files that
# are installed as part of the other packages in the conda environment e.g. fblas
os.add_dll_directory(op.join(CONDA_ENV, r'Library\bin'))

# tell python where the wood_pybind11*.pyd is located
os.add_dll_directory(COMPAS_WOOD_PATH)

# now we can import the module and test
from compas_wood.joinery import test

print(test)
test()

I also added a ticket to possibly improve this:

RH-80486 Investigate loading a conda environment directly in Rhino

1 Like

Thank you, going through the instructions, hopefully it will work on my machine too.

Interesting that it depends on these .dlls

    liblapack.dll
    libblas.dll
    python39.dll
    libcblas.dll
    KERNEL32.dll
    VCRUNTIME140.dll
    api-ms-win-crt-stdio-l1-1-0.dll
    api-ms-win-crt-heap-l1-1-0.dll
    api-ms-win-crt-runtime-l1-1-0.dll
    api-ms-win-crt-string-l1-1-0.dll

Which seems to be windows compilation dependencies.

When it comes to these kind of issues, how do you debug the whole process?

It works.

I need to buy you many beers…

1 Like

Do you think it would be possible to automate this process of linking these two directories similarly how egg-links are made?

Maybe. Not sure the extents of possibilities with egg-links files

I think the more failsafe approach would be to allow binding Rhino to a conda environment. It has a fully deployment of python (at least on windows) so it should theoretically be fairly easily possible. That’s what I made the ticket for.

1 Like