DevOps Buzz
Search…
⌃K

Cheat Sheet

Python tips and tricks.

Definitions / examples

Install multiple versions

Install all packages.
apt update
apt install python2.7 python2.7-dev
apt install python3.5 python3.5-dev
apt install python3.6 python3.6-dev
Update alternatives for python (2).
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 3
sudo update-alternatives --config python
Select python2.7
Update alternatives for python3.
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
sudo update-alternatives --config python3
Select python3.6
Fix pip.
sudo pip install pip --upgrade
sudo python3 -m pip uninstall pip
sudo apt install python3-pip --reinstall
wget https://bootstrap.pypa.io/get-pip.py
sudo python3.6 get-pip.py

Import module from parent dir

script_path = os.path.dirname(os.path.realpath(__file__))
root_path = f"{script_path}/../../../"
sys.path.insert(0, root_path)
from mymodule import myfile