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

Add example for embedding python in a C++ application #92

Open
JBPennington opened this issue Jul 15, 2024 · 8 comments
Open

Add example for embedding python in a C++ application #92

JBPennington opened this issue Jul 15, 2024 · 8 comments

Comments

@JBPennington
Copy link

I've started an example repo for embedding python in a C++ program and I'd like add it to the examples here. I'm having trouble getting the two example files to work. The goal is to use a hermetic C++ toolchain and hermetic python toolchain to produce a plot with matplotlib. I've cobbled this together from the other Issue How to set python interpreter within cc_binary #77

@JBPennington
Copy link
Author

Could someone help me at least get the plotting application up and running?

@rwgk
Copy link
Collaborator

rwgk commented Jul 16, 2024

Sorry I cannot help, except let you know that we've tragically lost our pybind11_bazel maintainer.

google/re2#502

I hope someone else will step up: Please contact me for admin permissions.

@jiawen
Copy link
Collaborator

jiawen commented Jul 16, 2024

Could someone help me at least get the plotting application up and running?

I can give it a shot. Can you point me to any necessary build instructions beyond the basics (I'm familiar with rules_python's hermetic Python toolchain but less so with a hermetic C++ one).

Is the issue the Python side with matplotlib?

@jiawen
Copy link
Collaborator

jiawen commented Jul 16, 2024

Sorry I cannot help, except let you know that we've tragically lost our pybind11_bazel maintainer.

google/re2#502

I hope someone else will step up: Please contact me for admin permissions.

Ouch, that's tragic news indeed. I'm an Xoogler and current active pybind11_bazel user. I'm happy to pitch in with maintaining the project in whatever capacity I can. @junyer and I worked on a few small PRs for this repo in the past.

@rwgk
Copy link
Collaborator

rwgk commented Jul 16, 2024

@jiawen I just sent an invite for adding you with admin permissions.

@rickeylev for awareness.

@JBPennington
Copy link
Author

JBPennington commented Jul 16, 2024

@jiawen Thanks for the help. Yes there are two binaries in the BUILD.bazel. One ("embed") is from the examples provided in the other issue. You can ignore that one.

The primary one I'm looking to get functional is "plot". I've had success with this using a local python repo and direct python calls, but I've had trouble reproducing that work with a hermetic python instance and pybind. The hermetic C++ toolchain works fine. The issue is currently in finding the associated libraries of the python toolchain (I think). I think the reason this worked with a local python instance is because it just used the local PATH variables to find the libraries needed (such as numpy).

@JBPennington
Copy link
Author

Sorry I cannot help, except let you know that we've tragically lost our pybind11_bazel maintainer.

google/re2#502

I hope someone else will step up: Please contact me for admin permissions.

I'm so sorry to hear that.

@JBPennington
Copy link
Author

I have an example up and running. https://github.com/JBPennington/pybind_cpp_w_python_example

The only current issue is that I can't create a cc_library with the python dependency because the current implementation requires setting env variables in the cc_binary or cc_test and cc_library doesn't support the env variable. It would be great to enforce that as a transitive property on the binary. I could instead set those as defines and set the env variables in the lib call.

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

No branches or pull requests

3 participants