mviereck / x11docker

Run GUI applications and desktops in docker and podman containers. Focus on security.
MIT License
5.64k stars 378 forks source link

The absence of `/usr/bin/python` will defeat `pyenv` to find an appropriate system python binary, which will in turn prevent `x11docker` from starting properly. #401

Closed hongyi-zhao closed 2 years ago

hongyi-zhao commented 2 years ago

I'm currently using pyenv as the Python version manager. And it seems that this will invalidate the python version judgment part of x11docker:

  # check python version
  Pythonbin="$(command -v python)"
  [ -z "$Pythonbin" ] && Pythonbin="$(command -v python3)"
  [ -z "$Pythonbin" ] && Pythonbin="$(command -v python2)"

For more details, see my tests below:

werner@X10DAi-00:~$ command -v python
/home/werner/.pyenv/shims/python
werner@X10DAi-00:~$ command -v python3
/home/werner/.pyenv/shims/python3
werner@X10DAi-00:~$ command -v python2
/home/werner/.pyenv/shims/python2

So, I think some code logic enhancements should be needed to handle this situation.

Regards, HZ

mviereck commented 2 years ago

Thank you for pointing on this. In fact, it doesn't matter for x11docker which python version is used. The check is only needed to find some arbitrary python binary.

hongyi-zhao commented 2 years ago

But in the pyenv case, as I've reported above, the following problem will be triggered by x11docker:

werner@X10DAi-00:~$ command -v python
/home/werner/.pyenv/shims/python
werner@X10DAi-00:~$ /home/werner/.pyenv/shims/python
pyenv: python: command not found

The `python' command exists in these Python versions:
  2.7.18
  3.10.1
  3.5.6
  3.6.10
  3.7.7
  3.8.3
  3.8.3/envs/socks5-haproxy
  3.8.3/envs/wannierberri
  3.9.1
  3.9.1/envs/aiida
  3.9.1/envs/datasci
  3.9.2
  3.9.2/envs/firedm
  3.9.7
  3.9.7/envs/kwant
  aiida
  datasci
  firedm
  kwant
  socks5-haproxy
  wannierberri

Note: See 'pyenv help global' for tips on allowing both
      python2 and python3 to be found.
mviereck commented 2 years ago

But how would one start python if the python command is invalid?

Edit: Currently I suspect a wrong pyenv setup.

hongyi-zhao commented 2 years ago

Edit: Currently I suspect a wrong pyenv setup.

Why? I've been using pyenv for a long time, and haven't seen anyone call the behavior described here a bug.

mviereck commented 2 years ago

Normal pathes are /usr/bin/python or /usr/bin/python3. The path /home/werner/.pyenv/shims/python indicates that it is provided by pyenv. But calling this command leads to an error. It should run your desired python version chosen with pyenv.

Edit: In a nutshell: On your system calling the command python leads to an error. This is independent from x11docker.

hongyi-zhao commented 2 years ago

Wonderful analysis. The problem is caused by the absence of /usr/bin/python on my system:

$ ls /usr/bin/python
ls: cannot access '/usr/bin/python': No such file or directory

To summarize: The absence of /usr/bin/python will defeat pyenv to find an appropriate system python binary, which will in turn prevent x11docker from starting properly. So, the fix is as follows:

$ apt-file search -x /usr/bin/python$
python-is-python2: /usr/bin/python        
python-is-python3: /usr/bin/python
$ sudo apt install -y python-is-python3
$ realpath -e /usr/bin/python
/usr/bin/python3.8
$ which python
/home/werner/.pyenv/shims/python
$ python --version
Python 3.8.10