Wiki Dashboard VPS1Euro

Guide client complet du dashboard: infrastructure, services, compte et support.

FR EN

Installer Python et pip (scripts et automatisation)

Mettre en place un environnement Python pour exécuter des scripts et automatiser des tâches.

A quoi sert ce tutoriel

Le tutoriel "Installer Python et pip (scripts et automatisation)" vous aide a atteindre cet objectif:

Mettre en place un environnement Python pour exécuter des scripts et automatiser des tâches.

← Retour aux tutoriels
1 profils 22 etapes 7 commandes ~20 min

Debian / Ubuntu

  1. Installer Python 3 et pip : apt install -y python3 python3-pip python3-venv
  2. Vérifier : python3 --version && pip3 --version
  3. --- Créer un environnement virtuel (bonne pratique) ---
  4. mkdir /opt/mon-script && cd /opt/mon-script
  5. python3 -m venv venv
  6. Activer l'environnement : source venv/bin/activate
  7. Installer des paquets : pip install requests flask pandas
  8. Désactiver l'environnement : deactivate
  9. --- Exécuter un script au démarrage (systemd) ---
  10. Créer /etc/systemd/system/mon-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. Activer le service : systemctl enable --now mon-script
  21. --- Planifier un script avec cron ---
  22. crontab -e puis ajouter : */5 * * * * /opt/mon-script/venv/bin/python /opt/mon-script/check.py