Skip to content

Instantly share code, notes, and snippets.

@ceccillia
Last active July 21, 2023 20:53
Show Gist options
  • Save ceccillia/52604a50e05e6ba8ea36748a85cf9266 to your computer and use it in GitHub Desktop.
Save ceccillia/52604a50e05e6ba8ea36748a85cf9266 to your computer and use it in GitHub Desktop.
Simply instruction for unix
1. Install venv
apt-get install python3-venv
2. Create venv
python3 -m venv venv_name
3. Enable venv
. /VENV_PATH/bin/activate
4. Create python file
mkdir / vi / chmod
5. Create systemd file
vi /etc/systemd/system/SERVICE_NAME.service
[Unit]
Description=Service Description
[Service]
Type=simple
User=root
ExecStart=/PATH_TO_VENV/bin/python3 /PATH_TO_PY_FILE/file.py
RestartSec=10
Restart=always
Restart=on-failure
[Install]
WantedBy=default.target
6. Reload and start systemd service
systemctl daemon-reload
systemctl enable SERVICE_NAME.service
systemctl start SERVICE_NAME.service
7. Debug
journalctl -f SERVICE_NAME.service
For changing python versions you can use pyenv or move this way:
apt-get install python3.8
sudo add-apt-repository -y ppa:deadsnakes/ppa (for ubuntu > 16.04) OR sudo add-apt-repository -y ppa:jblgf0/python
sudo apt-get update
sudo update-alternatives --config python3
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8
/usr/bin/python3.8 --automode
python3 --V
OR choose in "update-alternatives --config python3" with numbers
Dont forget to install venv and pip!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment