-
Notifications
You must be signed in to change notification settings - Fork 763
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 a note about pyenv in README and the guide #763
Conversation
But... how should we do when we want to use a static link? |
Here's my experiments note(on Arch Linux):
🤔 |
Co-Authored-By: Alexander Niederbühl <[email protected]>
Co-Authored-By: Alexander Niederbühl <[email protected]>
@Alexander-N |
|
||
To use PyO3 with pyenv, please set `--enable--shared` when builiding CPython. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary on all platforms or only on mac? I'm using pyenv on ubuntu and I do not remember setting that option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a macOS machine, but weirdly, Ubuntu 18.04 + Python 3.7.6(from pyenv) works but Arch Linux + Python 3.7.6 doesn't work.
There's certainly some OS-specific issue, but I still haven't detect it 😰
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess in this it's best to just document this as "you might --enable--shared
on some linux distributions"
FWIW I took a quick look at this today, and I think it might be a general issue when linking against a static Python lib, not just As far as I can tell, when you link an executable on unix against a static Python, only the symbols which the executable needs are included. But to run arbitrary python code when embedding the python interpreter in pyo3, all the Python interpreter symbols need to be in the final executable. Because the unused symbols are stripped out, this leads to the kind of failures seen on #742 and #762 when loading some other The correct fix might be we might have to disable certain functionality when linking statically. Or maybe there is a way to force all the symbols from I've asked at https://users.rust-lang.org/t/embed-whole-python-interpreter-using-static-linking/42509 , no response yet... |
On the topic of this being a general issue when linking against a static Python lib, I think I see the same issue with a conda environment on linux. ("Linux Mint 19.3", conda version : 4.8.2, conda-build version : 3.18.9, python 3.7.4.final.0) I could not get any combination of force_load options to work for static linking. It seems I could get it to work using that libpython.so. Not sure if that workaround is known or obvious, but at least I couldn't find it anywhere. |
Can confirm this is true. It even loads tensorflow so definitely a "working" solution.
I didn't know it and it's not obvious, so thank you very much for sharing this!
export PYTHON_SYS_EXECUTABLE=python3.8
export PYO3_CROSS_INCLUDE_DIR=$CONDA_PREFIX/include/python3.8
export PYO3_CROSS_LIB_DIR=$CONDA_PREFIX/lib
export PYTHONPATH=$CONDA_PREFIX/lib/python3.8
|
is this still relevant? |
I don't think we will merge this PR in this form. However, there is definitely scope to have a new section in the guide about "environment setup" which describes how to install Rust and Python for new users on a range of OSes, and macOS users would benefit from having this information about pyenv in that section. |
Should we maybe close this then and create a new issue? |
Created #2017 |
Closes #762 and #742
When using
pyo3
with pyenv,env PYTHON_CONFIGURE_OPTS="--enable-shared"
is required.