Skip to content

AttributeError: module 'nt' has no attribute '_add_dll_directory' #493

Closed

Description

@timfel

Reported by @JaroslavTulach

PS S:\windows> graalpy -m pip install numpy==1.26.4
Apr 01, 2025 7:13:16 AM org.graalvm.shadowed.org.jline.utils.Log logr
WARNING: Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
Looking in indexes: https://pypi.org/simple, https://www.graalvm.org/python/wheels/
Requirement already satisfied: numpy==1.26.4 in s:\windows\npt\lib\site-packages (1.26.4)

but then, when I try to import numpy:

import numpy
print ("OK")

I get:

PS S:\windows> graalpy n.py
Apr 01, 2025 7:14:23 AM org.graalvm.shadowed.org.jline.utils.Log logr
WARNING: Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
Traceback (most recent call last):
  File "S:\windows\n.py", line 1, in <module>
    import numpy
  File "S:\windows\npt\Lib\site-packages\numpy\__init__.py", line 111, in <module>
    _delvewheel_patch_1_10_0()
  File "S:\windows\npt\Lib\site-packages\numpy\__init__.py", line 108, in _delvewheel_patch_1_10_0
    os.add_dll_directory(libs_dir)
  File "S:\windows\bin\graalpy-community-24.2.0-windows-amd64\graalpy-community-24.2.0-windows-amd64\Lib\os.py", line 1119, in add_dll_directory
    cookie = nt._add_dll_directory(path)
AttributeError: module 'nt' has no attribute '_add_dll_directory'

Activity

  1. added 2 commits that reference this issue on Apr 10, 2025
    f35d2cc
    2177ebd
  2. added a commit that references this issue on Jul 15, 2025
    9704150
  3. eomasters-repos commented on Aug 13, 2025

    @eomasters-repos

    With version 24.1.2 I also got this error above when importing numpy on Windows.
    With version 24.2.2 I now get the following error:

    org.eomasters.pyrun.PyRunnerException: org.graalvm.polyglot.PolyglotException: ImportError: Error importing numpy: you should not try to import numpy from
            its source directory; please exit the numpy source tree, and relaunch
            your python interpreter from there.
    	at org.eomasters.pyrun.PyRunner.run(PyRunner.java:30)
    	at org.eomasters.pyeditor.gui.PyEditor.onRun(PyEditor.java:479)
    

    The used version is the only difference between the execution.

  4. msimacek commented on Aug 15, 2025

    @msimacek
    Contributor

    Hi @eomasters-repos, I could reproduce that, thank you for the report. It seems that _add_dll_directory currently doesn't work as expected. I'll open a new issue for fixing that. As a workaround, it should work when you find the numpy.libs directory and add it to the PATH variable before running GraalPy. Or rebuilding numpy from source should also work.

  5. timfel commented on Aug 18, 2025

    @timfel
    ContributorAuthor

    I just tested _add_dll_directory again and it does work, on my machine loading the dll shipped in our binary wheel simply does not work.

  6. msimacek commented on Aug 18, 2025

    @msimacek
    Contributor

    _add_dll_directory works in the sense that it does call the API, but it does nothing in the end because we don't set the right flags when loading libraries for it to take effect. I'm working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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