indygreg / PyOxidizer

A modern Python application packaging and distribution tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Filesystem-relative imports do not work from network locations on Windows

Skehmatics opened this issue · comments

commented

Steps to reproduce:

  1. Create a simple pyoxidizer.bzl config with filesystem-relative imports enabled
def make_exe():
    dist = default_python_distribution()
    policy = dist.make_python_packaging_policy()
    policy.resources_location = "filesystem-relative:lib"
    python_config = dist.make_python_interpreter_config()
    python_config.module_search_paths = ["$ORIGIN/lib"]
    python_config.run_command = "import ctypes; print(ctypes.get_errno())"

    exe = dist.to_python_executable(
        name="example",
        packaging_policy=policy,
        config=python_config,
    )
    return exe

def make_install(exe):
    files = FileManifest()
    files.add_python_resource("example", exe)
    return files

register_target("exe", make_exe)
register_target("install", make_install, depends=["exe"], default=True)

resolve_targets()
  1. Build using pyoxidizer build in a Windows environment
  2. Move the compiled output (including all its extra files) to an SMB share (either mapped or unmapped) and execute it

Expected behavior:
ctypes imports correctly and the program outputs 0

Actual behavior:
Program crashes when importing ctypes:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "ctypes", line 8, in <module>
ImportError: DLL load failed while importing _ctypes: The parameter is incorrect.

Using:

  • Pyoxidizer 0.24.0
  • Python 3.10.10
commented

Using a debugger, I can see that python310.dll makes a call to LoadLibraryExW using the lpFileName \\?\UNC\smbshare\example\lib\_ctypes.pyd which notably fails with the same error message as is present in the ImportError. An earlier call to LoadLibraryExW for the python3 dll did succeed, but it used a path like \\smbshare\example\python3 instead.

Likely related to https://gitlab.com/kornelski/dunce/-/issues/2 if that indeed is the issue