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]: Home .local libraries missing from sys.path with embed #4654

Open
3 tasks done
tdavidcl opened this issue May 5, 2023 · 2 comments
Open
3 tasks done

[BUG]: Home .local libraries missing from sys.path with embed #4654

tdavidcl opened this issue May 5, 2023 · 2 comments
Labels
triage New bug, unverified

Comments

@tdavidcl
Copy link

tdavidcl commented May 5, 2023

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

tags/v2.10.4

Problem description

the standard procedure to embed python in c++ using pybind lead to missing home libraries from sys.path.

Reproducible example code

CMakeLists.txt :

cmake_minimum_required(VERSION 3.1)

include(FetchContent)

add_executable(main ./main.cpp)

FetchContent_Declare(
  pybind11
  GIT_REPOSITORY https://github.com/pybind/pybind11.git
  GIT_TAG        v2.10.4
)

FetchContent_GetProperties(pybind11)
if(NOT pybind11_POPULATED)
  FetchContent_Populate(pybind11)
  add_subdirectory(./build/_deps/pybind11-src)
endif()

target_link_libraries(main pybind11::embed)

main.cpp

#include <pybind11/stl.h>
#include <pybind11/pybind11.h>
#include <pybind11/embed.h>
#include <pybind11/numpy.h>

namespace py = pybind11;

int main()
{
    py::scoped_interpreter guard{};

    py::exec("import sys\nprint(sys.path)");
}

running gives :

> cmake -B build .
> cd build
> make
> ./main 
['', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/usr/lib/python3.10/site-packages']

in normal python :

In [1]: import sys

In [2]: print(sys.path)
['/usr/bin', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '', '/home/xxx/.local/lib/python3.10/site-packages', '/usr/lib/python3.10/site-packages']

Is this a regression? Put the last known working version here if it is.

Not a regression

@tdavidcl tdavidcl added the triage New bug, unverified label May 5, 2023
@Lord-KA
Copy link

Lord-KA commented May 5, 2023

May be related with #4471.

@tdavidcl
Copy link
Author

tdavidcl commented May 9, 2023

Yes but the issue still exist, with the fix described by the PR ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New bug, unverified
Projects
None yet
Development

No branches or pull requests

2 participants