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

Long paths on Windows causes: FileNotFoundError: Could not find module ... (or one of its dependencies). #181

Open
axbycc-mark opened this issue Dec 10, 2024 · 0 comments

Comments

@axbycc-mark
Copy link

I'm not too familiar with this project, but I stumbled on this error when importing sklearn. The traceback reported the cause to be the following exception, where I have shortened the filepath for readability.

FileNotFoundError: Could not find module '...\site-packages\numpy.libs\libopenblas64__v0.3.23-293-gc2f4bdbb-gcc_10_3_0-2bde3a66a51006b2b53eb3' (or one of its dependencies). Try using the full path with constructor syntax.

The exception is triggered by _make_controller_from_path(filepath). The root cause is that the file path is truncated during the library discovery process. The actual file name is libopenblas64__v0.3.23-293-gc2f4bdbb-gcc_10_3_0-2bde3a66a51006b2b53eb373ff767a3f.dll. Truncation occurs because of the use of MAX_PATH, which is 260, in the line below.

buf = ctypes.create_unicode_buffer(MAX_PATH)

The error is resolved if I monkey-patch the above line to use MAX_PATH*2. An exacerbating factor is that I'm building my project using Bazel, which creates hermetic builds by playing a bunch of tricks with sandboxed and super-long path names. I can think of some simple work arounds and sanity checks.

  1. If the returned path is exactly MAX_PATH length, double the buffer size and call GetModuleFileNameExW again.
  2. Check that the returned path exists on the system. If not, double the buffer size and call GetModuleFileNameExW again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant