dgrunwald / rust-cpython

Rust <-> Python bindings
MIT License
1.81k stars 136 forks source link

Building library without python in system. #43

Open DoubleBoba opened 8 years ago

DoubleBoba commented 8 years ago

If i try to use this lib in my desktop env, it`s executing python code with the interpreter, that installed in system. But i want to use another way. I want to use a "portable" build of cpython in .so/.dll, that independent from system python. Is it realistic? If yes, how can i do it?

novocaine commented 8 years ago

It's based on the python in your PATH, and is designed to work with virtualenv. Have you tried running it from a virtualenv initialised with your custom interpreter?

On Monday, 21 March 2016, Tamtaradam notifications@github.com wrote:

If i try to use this lib in my desktop env, it`s executing python code with the interpreter, that installed in system. By i want to use another way. I want to use a "portable" build of cpython in .so/.dll, that independent from system python. Is it realistic? If yes, how can i do it?

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/dgrunwald/rust-cpython/issues/43

DoubleBoba commented 8 years ago

Thank you. But its not my way. I want to distribute my programm. And i want do it without installation of python in many types of envs (Linux, Windows, Mac). I think to do it with my own bindings to python. https://docs.python.org/3.5/extending/embedding.html. Thank you again.

novocaine commented 8 years ago

You just need to use a virtual env to compile your program.

Once that's done, you are free to copy around the compiled binary and its dependent shared libs like any other binary written in C; you wouldn't need Python installed.

On Tuesday, 22 March 2016, Tamtaradam notifications@github.com wrote:

Thank you. But its not my way. I want to distribute my programm. And i want do it without installation of python in many types of envs (Linux, Windows, Mac). I think to do it with my own bindings to python. https://docs.python.org/3.5/extending/embedding.html. Thank you again.

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/dgrunwald/rust-cpython/issues/43#issuecomment-199655869

AraHaan commented 7 years ago

hmm so I could use a venv in my python 3.5 on Windows to build things for 3.5 on mac and linux?

photex commented 6 years ago

Since this is still open I'd like to chime in that I have a similar requirement but for cross-compilation. It isn't clear to me how I can target a specific python build on my system when using --target=aarch64-linux-gnu. Looking over build.rs in python3-sys it appears that a great deal of work is being done that would require executing python.

svevang commented 6 years ago

I took a stab at a solution over in #131. It's an inversion of the typical virtualenv workflow and it allows bundling of python source inside the crate.

I've not investigated cross-compiling Python as part of the cargo build. Though I suppose anything is possible.

photex commented 6 years ago

Awesome. I'll take a look! Cross compiling python is pretty straightforward. Some trial and error went into a simple script that builds it for us so we can build our native modules for an alternate architecture. If it's something that could be translated into a cargo build script that'd be great.

svevang commented 6 years ago

131 leverages pyenv's python-build. The python-build tool uses environment variables to hook into the python building process. @photex Perhaps that could be adapted to cross compiling?

Note that python3-sys invokes the python interpreter as part of the build process. This is done to set up various rust cfg flags . So there is a build time dependency on the python interpreter being present and able to be executed by the build system. @photex here's a rough sketch of a workaround to that build time dependency, as part of 131.