This is a cheat-sheet-style article based on information found on other online resources including manuals for Python, Virtual Environments, StackOverflow articles, etc
Objective:
-
A bare Centos 7 or Ubuntu comes with Python 2 and Python 3.8. We need Python 3.9
-
Some OS utilities may install Python 3 as dependencies. Don't want to touch them to not break anything else
-
Hence, installing under local user will side step any dependency conflicts and allow a dedicated Python3.9 installation that can be used for Zapy SDK
-
Benefit - removing/reinstalling/upgrading this local Python3 installation becomes simple
Steps
-
With sudo/root privileges for this step only, install OS level dependency packages
CentOS
sudo yum install gcc zlib zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi libffi-devel lzma
Ubuntu
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
-
NOTE - If you are missing some of these dependencies, and still try to install python, you might have to reinstall..!
-
For the rest of these steps, do not use sudo/root
-
Python3.9 installation as regular user
version=3.9.12 version_short=3.9 wget https://www.python.org/ftp/python/$version/Python-$version.tgz tar xzf Python-$version.tgz cd Python-$version ./configure --enable-optimizations --enable-shared --prefix=$HOME/python$version LDFLAGS=-Wl,-rpath=$HOME/python$version/lib make -j 8 # for faster build time j is number of cores to use. Get number from nproc
make altinstall # so it does not trash installed python2 or other system-preinstalled python version python$version_short -V echo "export PATH=$HOME/python$version/bin/:$PATH" >> ~/.bashrc echo "export PYTHONPATH=$HOME/python$version/bin" >> ~/.bashrc export PATH=$HOME/python$version/bin/:$PATH export PYTHONPATH=$HOME$version/python/bin
-
Virtual Environment configuration as regular user
~/python$version/bin/python$version_short -m venv ~/venv_3 source ~/venv_3/bin/activate pip install --upgrade pip setuptools # optional: echo "source ~/venv_3/bin/activate" >> ~/.bashrc
Comments
0 comments
Please sign in to leave a comment.