rust-cpython icon indicating copy to clipboard operation
rust-cpython copied to clipboard

Building library without python in system.

Open DoubleBoba opened this issue 9 years ago • 8 comments

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?

DoubleBoba avatar Mar 21 '16 04:03 DoubleBoba

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 [email protected] 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

novocaine avatar Mar 21 '16 05:03 novocaine

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.

DoubleBoba avatar Mar 22 '16 06:03 DoubleBoba

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 [email protected] 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

novocaine avatar Mar 22 '16 07:03 novocaine

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

AraHaan avatar Dec 21 '16 06:12 AraHaan

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.

photex avatar Mar 23 '18 12:03 photex

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.

svevang avatar Apr 01 '18 19:04 svevang

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.

photex avatar Apr 01 '18 19:04 photex

#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.

svevang avatar Apr 02 '18 15:04 svevang