Skip to content

Detecting Python.h when using an uv venv to setup a project #1156

@jacopoabramo

Description

@jacopoabramo

I recently opened a discussion which was answered today about using an uv virtual environment to manage the installation of nanobind.

I'm developing my project in VSCode with a c_cpp_properties.json file that looks like this:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/.venv/Lib/site-packages/nanobind/include",
            ]
        }
    ],
    "version": 4
}

and a settings.json that looks like this:

{
    "cmake.configureOnOpen": true,
    "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
}

When using VSCode CMake extension to try and configure the project, it complained that it couldn't find the location of Python.h. The suggested example, which I was later told relied on FindPython, was relying on the python interpreter of the virtual environment - which does not ship itself the include folders. This is actually cached in a user folder which can be retrieved via python3 -c "import sysconfig; print(sysconfig.get_path('include'))".

Since it's a bit annoying having to manually copy-pasting the location of the include folder everytime, is there an alternative approach that relies on environment variables of some sort?

I apologize if this is a known issue (or if it's not an issue at all), feel free to close in case it's a duplicate.

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