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

Unable to use radian with pyenv- or rtx-installed Pythons when libpython3.11 is installed on Debian #456

Open
adamroyjones opened this issue Dec 31, 2023 · 0 comments

Comments

@adamroyjones
Copy link

adamroyjones commented Dec 31, 2023

The below is derived from pyenv/pyenv#2875.

I've had issues attempting to use an rtx-installed Python to install and run radian on Debian Bookworm. I've narrowed it down to the fact that radian manipulates LD_LIBRARY_PATH as part of its startup routine, specifically

radian/radian/app.py

Lines 112 to 114 in 89bc7a3

os.environ[ld_library_var] = LD_LIBRARY_PATH
if sys.argv[0].endswith("radian"):
os.execv(sys.argv[0], sys.argv)

This leads LD_LIBRARY_PATH to include /usr/lib/x86_64-linux-gnu (on my machine). If libpython3.11 is installed, then the call to os.execv leads to a different Python interpreter—the system's interpreter, which does not have radian installed—to be started. I've a minimal reproduction of the general issue below.

If I modify radian to not modify LD_LIBRARY_PATH, things seem fine.

Do you have any ideas?


Take the two (scrappy) files below.

# main.py
import os
import sys

print(f"main.py :: {sys.version}")
py = "/root/.pyenv/shims/python"
os.environ["LD_LIBRARY_PATH"] = "/usr/lib/x86_64-linux-gnu"
os.execv(py, [py])
# Dockerfile
FROM debian:bookworm

RUN apt-get update && \
  apt-get install --yes \
    curl git \
    build-essential libssl-dev zlib1g-dev \
    libbz2-dev libreadline-dev libsqlite3-dev \
    libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

RUN curl https://pyenv.run | bash

RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
RUN echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
RUN echo 'eval "$(pyenv init -)"' >> ~/.bashrc

RUN /root/.pyenv/bin/pyenv install 3.11.7
RUN /root/.pyenv/bin/pyenv global 3.11.7

ADD ./main.py main.py

Then run

docker image build --tag=radian-reprex:latest .
docker container run -it radian-reprex:latest bash

Inside of the container, python is Python 3.11.7 (installed by pyenv) and python main.py opens a second Python 3.11.7 interpreter, but

apt install --yes libpython3.11
python main.py

leads Python 3.11.7 (installed by pyenv) to open a Python 3.11.2 interpreter. This is the system interpreter.

Note the following.

  • The above happens if libpython3.11 is installed before pyenv is installed.
  • The above hinges on the presence of /usr/lib/x86_64-linux-gnu/libpython3.11.so.1.0.
  • The above happens if pyenv installs Pythons with env PYTHON_CONFIGURE_OPTS="--enable-shared" set.
  • The above does not happen if LD_LIBRARY_PATH is unset.
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

1 participant