Note: as of August 2022 Python 3.10 and Python 3.11 are pre-installed on all Opalstack servers.
You can install your own Python from source while in a SSH session as follows, just adjust the PYVER
variable for the version you need:
export PYVER=3.9.0
mkdir -p ~/src ~/tmp ~/opt
export TMPDIR=~/tmp
cd ~/src
wget https://www.python.org/ftp/python/$PYVER/Python-$PYVER.tgz
tar zxf Python-$PYVER.tgz
cd Python-$PYVER
./configure --prefix=$HOME/opt
make
make install
When that's done you'll have your new Python available at ~/opt/bin/pythonX.Y
with its libraries available in ~/opt/lib/pythonX.Y
.
That will work for reasonably recent versions of Python, ie 2.7+. If you need something older then you can install patched versions of Python with pyenv eg:
mkdir -p ~/tmp
export TMPDIR=~/tmp
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
exec "$SHELL"
pyenv install 2.5.5
export PYENV_VERSION=2.5.5
In either case in order to use the new Python with a uwsgi or Django app installed via your dashboard, you'll need to replace the installed env
virtualenv directory with a new one created with your self-installed Python and then install uwsgi and whatever other packages you need into that, eg:
cd ~/apps/appname
mv env env.old
~/opt/bin/python3.9 -m venv env
source env/bin/activate
pip install uwsgi django