Git Product home page Git Product logo

Comments (7)

marcpabst avatar marcpabst commented on June 23, 2024

Looks like Python is not automatically searching $PATH from v3.8 onwards, it works if you use os.add_dll_directory(). Should maturin/PyO3 handle this?

from maturin.

messense avatar messense commented on June 23, 2024

How should maturin handle this? What's the right argument to pass to os.add_dll_directory()?

from maturin.

marcpabst avatar marcpabst commented on June 23, 2024

Good queston. os.add_dll_directory() needs to be called with each directory to look for DLLs in for. Could we maybe have an option to just add everything in PATH to os.add_dll_directory() when importing? The alternative is some form of bundling, but that can cause license issues.

I'm still not sure why it just works on MacOS.

for context: https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew

from maturin.

messense avatar messense commented on June 23, 2024

IMHO, for security it should be left for the library/user to call os.add_dll_directory(), doing in in maturin/pyo3 unconditionally seems worrisome.

from maturin.

marcpabst avatar marcpabst commented on June 23, 2024

What are the security implications you're worried about? IMHO this is the standard for system-wide dynamic DLLs and most Python modules that present bindings to C libs will search PATH. I generally think that it's highly unintuitive to require a library user to call os.add_dll_directory() before importing things. You can't even have your library handle this (by letting the user specify a search path), because linked libraries will always be loaded upon imports (I think).

So there needs to be some sort of way to either tell maturin or poy3 to add PATH, or to inject custom python code before the module DLL is loaded. I'm not suggesting this should happen unconditionally for every module, but for some modules this will just be required.

from maturin.

messense avatar messense commented on June 23, 2024

What are the security implications you're worried about?

The doc says:

DLL dependencies for extension modules and DLLs loaded with ctypes on Windows are now resolved more securely.

If there isn't any security implication, you'd want python to handle it automatically, right?

Anyway, I suggest you use a mixed Python/Rust project layout and add os.add_dll_directory() call before importing the Rust extension module.

from maturin.

marcpabst avatar marcpabst commented on June 23, 2024

Thats probbaly the way to go, thanks! Maybe worth documenting as the standard error when trying to import on Windows is not very helpful.

from maturin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.