indygreg / PyOxidizer

A modern Python application packaging and distribution tool
Mozilla Public License 2.0
5.32k stars 227 forks source link

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

Open Skehmatics opened 1 year ago

Skehmatics commented 1 year ago

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()

2. Build using `pyoxidizer build` in a Windows environment
3. 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 "", line 1, in File "ctypes", line 8, in ImportError: DLL load failed while importing _ctypes: The parameter is incorrect.



Using:
+ Pyoxidizer 0.24.0
+ Python 3.10.10
Skehmatics commented 1 year ago

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