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

Could there be an os independent wrapper around things like Py_SetPythonHome? #736

Open
gilescope opened this issue Jan 17, 2020 · 4 comments

Comments

@gilescope
Copy link
Contributor

Could there be an os independent wrapper around things like Py_SetPythonHome? It's not the most rustic of ffi interfaces and the sizes change between windows and linux.

@davidhewitt
Copy link
Member

Sorry for the delayed response here. What would your example use case be for Py_SetPythonHome ? I've never come across a situation where I've needed to change the python library location (virtualenvs?), but that could just be me.

@JJsrc
Copy link

JJsrc commented Feb 21, 2020

The reason is we are using conda, and therefore python is not in the "standard location". This breaks the python interpreter initialization code, unless you have pythonhome set.
And setting it today requires a bit of platform specific code in the vein of :
unsafe { #[cfg(windows)] let raw_ptr = WideCString::from_str(conda_prefix).unwrap().into_raw(); #[cfg(not(windows))] let raw_ptr = WideCString::from_str(conda_prefix).unwrap().into_raw() as *mut i32; pyo3::ffi::Py_SetPythonHome(raw_ptr); };

Online python doc explaining: https://docs.python.org/2.0/api/embedding.html

@gilescope
Copy link
Contributor Author

(We are using setuptools-rust not maturin if thst sheds any light. I am guessing at some point we should switch over?)

Sent with GitHawk

@davidhewitt
Copy link
Member

All of the above sounds reasonable. We could easily add some wrappers for these functions.

Just one stupid question - I'm assuming you have reasons why you want to use this function rather than set the PYTHONHOME env var?

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

No branches or pull requests

3 participants