> For the complete documentation index, see [llms.txt](https://www.devops.buzz/public/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.devops.buzz/public/python/cheat-sheet.md).

# Cheat Sheet

## Definitions / examples

{% embed url="<https://github.com/gto76/python-cheatsheet>" %}

{% embed url="<https://github.com/geekcomputers/Python>" %}

{% embed url="<https://github.com/vinta/awesome-python>" %}

## Install multiple versions

Install all packages.

```bash
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).

```bash
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.

```bash
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.

```bash
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

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