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

[Bug] venv created by uv works not well with pyo3 #12343

Open
clouds56 opened this issue Mar 20, 2025 · 5 comments
Open

[Bug] venv created by uv works not well with pyo3 #12343

clouds56 opened this issue Mar 20, 2025 · 5 comments
Labels
bug Something isn't working windows Specific to the Windows platform

Comments

@clouds56
Copy link

Summary

Like #10598, when build project using pyo3 with uv-managed python, but for windows.
It would build successfully but could not run since no python.dll found

env:

VIRTUAL_ENV=D:\S\agent\.venv

log for build

[pyo3-ffi 0.24.0] cargo:rustc-link-lib=pythonXY:python313
[pyo3-ffi 0.24.0] cargo:rustc-link-search=native=C:\Users\clouds\AppData\Local\Programs\Python\Python313\libs

dependencies of built exe

ldd target\debug\deps\engine-2d69d82a736905e2.exe
        ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7ffc7f660000)
        KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7ffc7ea40000)
        KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll (0x7ffc7cbe0000)
        apphelp.dll => /c/WINDOWS/SYSTEM32/apphelp.dll (0x7ffc796c0000)
        bcryptprimitives.dll => /c/WINDOWS/System32/bcryptprimitives.dll (0x7ffc7d330000)
        ucrtbase.dll => /c/WINDOWS/System32/ucrtbase.dll (0x7ffc7d1e0000)
        VCRUNTIME140.dll => /c/WINDOWS/SYSTEM32/VCRUNTIME140.dll (0x7ffc5fae0000)
        userenv.dll => /c/WINDOWS/SYSTEM32/userenv.dll (0x7ffc7bcf0000)
        RPCRT4.dll => /c/WINDOWS/System32/RPCRT4.dll (0x7ffc7e920000)
        python313.dll => not found
        api-ms-win-crt-math-l1-1-0.dll => /c/Program Files/Microsoft Visual Studio/2022/BuildTools/Common7/IDE/api-ms-win-crt-math-l1-1-0.dll (?)
        api-ms-win-crt-runtime-l1-1-0.dll => /c/Program Files/Microsoft Visual Studio/2022/BuildTools/Common7/IDE/api-ms-win-crt-runtime-l1-1-0.dll (?)
        api-ms-win-crt-stdio-l1-1-0.dll => /c/Program Files/Microsoft Visual Studio/2022/BuildTools/Common7/IDE/api-ms-win-crt-stdio-l1-1-0.dll (?)
        api-ms-win-crt-locale-l1-1-0.dll => /c/Program Files/Microsoft Visual Studio/2022/BuildTools/Common7/IDE/api-ms-win-crt-locale-l1-1-0.dll (?)
        api-ms-win-crt-heap-l1-1-0.dll => /c/Program Files/Microsoft Visual Studio/2022/BuildTools/Common7/IDE/api-ms-win-crt-heap-l1-1-0.dll (?)

Shall we copy python313.dll to .env/Scripts like what python -m venv .venv does (see also pypa/virtualenv#1050 (comment))

Platform

Windows 11 x86_64

Version

0.6.0

Python version

Python 3.13.2

@clouds56 clouds56 added the bug Something isn't working label Mar 20, 2025
@buptsad
Copy link

buptsad commented Mar 29, 2025

Got similar error, and solved by manually copy the dll into the Scripts folder. It surely requires a copy or hard link to python dll.

@zanieb zanieb added the windows Specific to the Windows platform label Apr 1, 2025
@zanieb
Copy link
Member

zanieb commented Apr 1, 2025

cc @geofft

@Svalorzen
Copy link

Svalorzen commented Apr 2, 2025

Same exact issue here, on multiple Mac machines: I'm compiling a C++ project using CMake, with the following script:

    # Create empty venv
    find_program (UV_PATH uv REQUIRED)
    execute_process(
        COMMAND "${UV_PATH}" venv "${VENV_FOLDER}" --python ${PYTHON_VERSION} --managed-python
    )

    # Find Python and related dev libraries that match the venv
    # Note that headers should be provided by uv, but might be in the uv local cache folder (not in the venv itself)
    # You can print ${Python3_INCLUDE_DIRS} to make sure it's not using system-wise ones.
    set(Python3_ROOT_DIR "${VENV_FOLDER}")
    find_package(Python3 COMPONENTS Interpreter Development REQUIRED)

CMake correctly identifies the CPython library in .local, but otool -D shows how the final executables are searching the library in the wrong install path:

dyld[95593]: Library not loaded: /install/lib/libpython3.13.dylib

One weird thing is that on one mac everything seems to work correctly, but that mac doesn't have a root /install folder; perhaps that has something to do with it.

@zanieb
Copy link
Member

zanieb commented Apr 2, 2025

@Svalorzen please open a new issue instead of adding a different case to an existing one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working windows Specific to the Windows platform
Projects
None yet
Development

No branches or pull requests

4 participants