Note: the following Python versions are pre-installed on all Opalstack servers: 2.7, 3.6, 3.10, 3.11, 3.12
2023-11-28: updated to include OpenSSL build instructions.
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:
# prep
mkdir -p ~/src ~/tmp ~/opt
export TMPDIR=~/tmp
# build openssl
cd ~/src
export OPENSSL_VER=1.1.1s
wget https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz
tar -xvf openssl-$OPENSSL_VER.tar.gz
rm -rf openssl-$OPENSSL_VER.tar.gz
mv openssl-$OPENSSL_VER openssl
cd openssl
./config --prefix=$HOME/opt/ssl --openssldir=$HOME/opt/ssl
make
make install
# build python
cd ~/src
export PYVER=3.9.0
wget https://www.python.org/ftp/python/$PYVER/Python-$PYVER.tgz
tar zxf Python-$PYVER.tgz
cd Python-$PYVER
./configure --prefix=$HOME/opt --with-openssl=$HOME/opt/ssl --with-openssl-rpath=auto
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:
# prep
mkdir -p ~/src ~/tmp ~/opt
export TMPDIR=~/tmp
# build openssl
cd ~/src
export OPENSSL_VER=1.1.1s
wget https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz
tar -xvf openssl-$OPENSSL_VER.tar.gz
rm -rf openssl-$OPENSSL_VER.tar.gz
mv openssl-$OPENSSL_VER openssl
cd openssl
./config --prefix=$HOME/opt/ssl --openssldir=$HOME/opt/ssl
make
make install
# install pyenv
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"
# install python
env CONFIGURE_OPTS="-with-openssl=$HOME/opt/ssl -with-openssl-rpath=auto" 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
scl enable devtoolset-11 -- pip install uwsgi django