Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python bindings + Windows/Conda: dependent libraries of the *.pyd library cannot be found #507

Open
2 tasks
peci1 opened this issue Sep 21, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@peci1
Copy link
Contributor

peci1 commented Sep 21, 2022

Environment

  • OS Version: Windows 10 Conda
  • Source or binary build? Source gz-math7 built according to the tutorial

Continuation of discussion from gazebosim/sdformat#1165 (comment) .

Python 3.8+ no longer looks into PATH when looking for dependencies of external binary modules. Paths to the dependencies have to be added by calling os.add_dll_directory(). Normally, gz-math7.dll is installed in install/bin, while the *.pyd module is installed in install/lib/python. Therefore, Python doesn't examine install/bin for the dependencies and import gz.math7 fails with error:

ImportError: DLL load failed while importing gz.math7: module not found

Unfortunately, Windows cannot tell which library failed to load, but experimentally, copying everything from install/bin to install/lib/python resolves the issue. However, that is not a suitable solution. If I manually call os.add_dll_directory(abs_path+"/install/bin"), importing the module works.

Now the question is where to put the add_dll_directory() call and what kind of path to pass to it. The most practical way I see is creating wrapper pure python modules which would just call the add_dll_directory() and the load the binary module. This would need some renaming around, but should be the most straight-forward way.

Regarding the path to add, I've seen people on the internet to just add all directories from PATH via add_dll_directory(), but I'd say this kind of goes against the direction set by Python 3.8 (looking in PATH was discarded to increase security; although I'm a bit hesitant if it actually helps if an attacker can still push a malicious .pyd file).

Things to resolve:

  • Where to add os.add_dll_directory()?
  • What kind of path (hardcoded/relative/...) should be passed to the above call?
@peci1 peci1 added the bug Something isn't working label Sep 21, 2022
@traversaro
Copy link
Contributor

What kind of path (hardcoded/relative/...) should be passed to the above call?

Related to that, I checked what ROS2-related code does, and in several point it calls:

add_dll_directories_from_env('PATH')

effectively reverting to pre-Python 3.8 behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In progress
Development

No branches or pull requests

3 participants