0

I'm getting some weird behaviour when running python....

# which python
/root/.pyenv/shims/python
# /root/.pyenv/shims/python -V
Python 3.9.7
# python -V
Python 3.8.10

Like waaaatttt!!

So I check my PATH... looks good

# echo $PATH
/root/.pyenv/bin:/root/.pyenv/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

What is going on?!

The system is installed from a Dockerfile...

FROM ubuntu:20.04

# set shell locale to UTF8
ENV LANG=C.UTF-8

# system utils
RUN apt-get update && apt-get upgrade -y && \
    apt-get install -qq wget curl git zip jq

# python build libraries
RUN DEBIAN_FRONTEND="noninteractive" \
    apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
    libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils \
    tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev python3-pip && \
    ln -s /usr/bin/python3 /usr/bin/python

# pyenv - used to set the build version of a python package
# Usage: pyenv install 3.9.7 && pyenv global 3.9.7
RUN git clone https://github.com/pyenv/pyenv.git ~/.pyenv && \
    echo 'export PATH="$HOME/.pyenv/bin:$HOME/.pyenv/shims:$PATH"' >> ~/.bashrc

and then I install and enable the required version of python with...

# pyenv install 3.9.7
Downloading Python-3.9.7.tar.xz...
-> https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tar.xz
Installing Python-3.9.7...
Installed Python-3.9.7 to /root/.pyenv/versions/3.9.7
# pyenv global 3.9.7

# pyenv which python
/root/.pyenv/versions/3.9.7/bin/python
# /root/.pyenv/versions/3.9.7/bin/python -V
Python 3.9.7

# which python
/root/.pyenv/shims/python
# /root/.pyenv/shims/python -V
Python 3.9.7
# python -V
Python 3.8.10

At least pip works...

# pip -V
pip 21.2.3 from /root/.pyenv/versions/3.9.7/lib/python3.9/site-packages/pip (python 3.9)
# pip3 -V
pip 21.2.3 from /root/.pyenv/versions/3.9.7/lib/python3.9/site-packages/pip (python 3.9)

UPDATE FOR @tripleee

# type -a python
python is /root/.pyenv/shims/python
python is /usr/bin/python
python is /bin/python
Christian
  • 3,708
  • 3
  • 39
  • 60
  • Probably this is just more proof that you should never use `which`. What is the output of the recommended replacement `type -a python`? What version of `which` are you using? – tripleee Oct 24 '21 at 11:39
  • @tripleee added in the result. Ironically, if you run this outside of a Dockerfile, it works. – Christian Oct 24 '21 at 14:31
  • Where do you have a `Dockerfile`? What does it do? – tripleee Oct 30 '21 at 07:16
  • There is no indication that you ever activate the `pyenv`. I guess the problem manifests when you `docker run` something. Your shell is not invoked at all (unless of course you `docker run yourimage bash -c ...`) This seems like a basic misunderstanding of how Docker works ... But I'm still not sure it's clear enough. – tripleee Oct 30 '21 at 07:48

0 Answers0