installing Python

Description

I am trying to install a Python web app on a site and I’m running into difficulty trying to understand the instructions for Python in the docs.

As the user, it looks like Python is not available at all.

$ python3 —version
-bash: python3: command not found

As root, I can see that there is a very old version of Python on the machine. I don’t know whether/how I am supposed to upgrade it or install another version, nor do I know how to make it available to the user.

[root]# which python3
/usr/bin/python3
[root]# python3 --version
Python 3.6.8

Is there some setup I need to do to make (a current version of) Python available to the user account?

Use pyenv

pyenv install 3.4.1
# Switch to 3.4.1 locally
pyenv local 3.4.1
# Set 3.4.1 as the default system interpreter for future logins
pyenv global 3.4.1

Thanks for the encouragement to try harder. I had tried this command already, but I got nervous when I saw an error. After a couple tries I made some progress.

# pyenv install 3.12.8
python-build: TMPDIR=/tmp cannot hold executables (partition possibly mounted with `noexec`)
# TMPDIR=/var/tmp pyenv install 3.12.8
Downloading Python-3.12.8.tar.xz...
-> https://www.python.org/ftp/python/3.12.8/Python-3.12.8.tar.xz
Installing Python-3.12.8...
Installed Python-3.12.8 to /usr/local/share/python/pyenv/versions/3.12.8
# pyenv global 3.12.8
# python3 --version
Python 3.12.8

Unfortunately, I still don’t see a working python from my user shell. I tried systemctl reload fsmount just in case, but that didn’t help. As the user, I do see /bin/python3 but it is a broken symlink pointing to /etc/alternatives/python3. Likewise, /bin/pyenv is a broken symlink pointing to /usr/local/share/python/pyenv/bin/pyenv.

You’re installing globally, which would make it available to all users.

In this context, flip into the user’s shell - ensure ssh service is enabled for the user - then you can set per-directory:

# Install:
TMPDIR=/var/tmp pyenv install 3.12.8

# Downloading Python-3.12.8.tar.xz...
# -> https://www.python.org/ftp/python/3.12.8/Python-3.12.8.tar.xz
# Installing Python-3.12.8...
# Installed Python-3.12.8 to /usr/local/share/python/pyenv/versions/3.12.8

# Flip into site1
su site1

pyenv versions

# Reports:
#  3.12.8
#  pypy3.10-7.3.17

# Use 3.12.8
pyenv global 3.12.8

python --version
# Reports: Python 3.12.8

which python
# Reports: /usr/local/share/python/pyenv/shims/python

From there, you can configure the default version using a file named .python-version that contains a single line which represents any component of the version (major, major + minor, full).

Use the shim path (/usr/local/share/python/pyenv/shims/python) to ensure pyenv is loaded, which in turn handles any-version population.

This is also part of the API as the “python” module.

cpcmd -d DOMAIN python:install 3.12.8
# Autosource latest 3.12...
cpcmd -d DOMAIN python:make-default 3.12 /var/www/app

OK, so it looks like there’s a problem with a particular user account (just happens it’s the one I was trying to test on). I checked a different user and it looks like python is there as you describe.

[root ~]# su site6
[site6 /]$ pyenv versions
* 3.12.8 (set by /usr/local/share/python/pyenv/version)
[site6 /]$ exit
exit
[root ~]# su site3
bash: /usr/local/share/go/goenv/libexec/../completions/goenv.bash: No such file or directory
[site3 /]$ pyenv versions
bash: pyenv: command not found

[edit] some additional poking around … about half of my sites don’t have a working pyenv. I can’t identify any pattern, they include older sites and newer sites. I created a test site just now and that one worked. Missing pyenv corellates with the goenv.bash error, fwiw.

Enable ssh service for the site. If that is enabled, then a whiteout exists on /usr/local/share for that site. This occurs if the user rm -rf’d /usr/local/share or any component within.

Removing the opaque property using setfattr under shadow/, then running systemctl reload fsmount will clear the cache.

Thank you! I have no idea how it got that way, but setfattr -n trusted.overlay.opaque -v n /home/virtual/site3/shadow/usr/local seems to have fixed it.

1 Like