DevOps Buzz
Search…
Bash / Shell
Bitbucket
Distros
Elasticsearch
General
Guidelines / Standards
microk8s
Prometheus
RabbitMQ
VirtualBox
Cheat Sheet
Python tips and tricks.

Definitions / examples

GitHub - gto76/python-cheatsheet: Comprehensive Python Cheatsheet
GitHub
GitHub - geekcomputers/Python: My Python Examples
GitHub
GitHub - vinta/awesome-python: A curated list of awesome Python frameworks, libraries, software and resources
GitHub

Install multiple versions

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

Import module from parent dir

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