VPS1Euro Dashboard Wiki

Complete client guide: infrastructure, services, account and support.

FR EN

Install Python and pip (scripts and automation)

Set up a Python environment to run scripts and automate tasks.

What this tutorial does

The tutorial "Install Python and pip (scripts and automation)" helps you achieve this goal:

Set up a Python environment to run scripts and automate tasks.

← Back to tutorials
1 profiles 22 steps 7 commands ~20 min

Debian/Ubuntu

  1. Install Python 3 and pip: apt install -y python3 python3-pip python3-venv
  2. Check: python3 --version && pip3 --version
  3. --- Create a virtual environment (best practice) ---
  4. mkdir /opt/mon-script && cd /opt/mon-script
  5. python3 -m venv venv
  6. Activate environment: source venv/bin/activate
  7. Install packages: pip install requests flask pandas
  8. Disable environment: deactivate
  9. --- Run a script at startup (systemd) ---
  10. Create /etc/systemd/system/my-script.service:
  11. [Unit]
  12. Description=Mon script Python
  13. After=network.target
  14. [Service]
  15. ExecStart=/opt/mon-script/venv/bin/python /opt/mon-script/app.py
  16. Restart=always
  17. User=deploy
  18. [Install]
  19. WantedBy=multi-user.target
  20. Activate the service: systemctl enable --now mon-script
  21. --- Schedule a script with cron ---
  22. crontab -e then add: */5 * * * * /opt/mon-script/venv/bin/python /opt/mon-script/check.py