randy3k / radian

A 21 century R console
MIT License
1.96k stars 73 forks source link

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

Open adamroyjones opened 6 months ago

adamroyjones commented 6 months ago

The below is derived from https://github.com/pyenv/pyenv/issues/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

https://github.com/randy3k/radian/blob/89bc7a3690444e2bacb26eb1dcfbc76da4e2e343/radian/app.py#L112-L114

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.