#1 Le 03/06/2025, à 17:50
- f6aap
Compiler un script Python pour avoir un executable ubuntu
Bonjour,
Je souhaite compiler un script Python pour avoir un exécutable sous Ubuntu.
Merci pour vos réponses,
Cordialemnt
Hors ligne
#2 Le 03/06/2025, à 18:44
- kamaris
Re : Compiler un script Python pour avoir un executable ubuntu
Un script est par définition un programme qui ne se compile pas mais s'interprète, avec un interpréteur : https://fr.wikipedia.org/wiki/Langage_de_script
Ici python :
python nom-du-script
Mainteneur Xfce : https://gravatar.com/gaelbonithon
Hors ligne
#3 Le 03/06/2025, à 20:16
- nany
Re : Compiler un script Python pour avoir un executable ubuntu
Bonjour,
Ça n’a pas l’air très simple mais c’est faisable : Utiliser PyInstaller et Cython pour créer un exécutable Python.
En ligne
#4 Le 04/06/2025, à 11:07
- f6aap
Re : Compiler un script Python pour avoir un executable ubuntu
Bonjour
Merci pour votre réponse.
la commande d'installation de Pyinstaller bug
daniel@hp:~$ pip install --upgrade pyinstaller
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.
See /usr/share/doc/python3.12/README.venv for more information.
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
Merci de m'aider !
Cordialement
Hors ligne
#5 Le 04/06/2025, à 14:27
- MPython Alaplancha
Re : Compiler un script Python pour avoir un executable ubuntu
Bonjour.
Petite mise au point sur les termes employés. Pyinstaller ne compile pas comme le ferait un langage compilé(comme le c). Il empaquète plutôt un code python avec son interpréteur et ses dépendances. Ton exécutable ne fonctionnera que sur la plateforme sur laquelle tu le crées .
Pour ta question sur son installation, tu dois utiliser un environnement virtuel comme venv.
https://www.commentcoder.com/python-venv/ (1er lien trouvé . utilise python3 et non python comme décrit sur ce site)
Quel est ton but au juste?
# Debian12 Mate
Hors ligne
#6 Le 04/06/2025, à 17:46
- f6aap
Re : Compiler un script Python pour avoir un executable ubuntu
Merci MPython Alaplancha
Mon but est de diffuser un exécutable sur plusieurs postes et ne pas permettre la modification.
Je dispose de ce tutoriel (voir ci-dessous ) mais qui ne fonctionne plus
Comment compiler un script python pour Linux :
Étape1:
Pour Linux, nous pouvons également utiliser la bibliothèque pyinstaller, mais pour compiler le script python pour Linux, nous devons effectuer ce processus sur un système Linux, sinon il créera automatiquement un fichier .exe
Pour installer pyinstaller, utilisez la commande suivante dans le terminal.
pip3 install pyinstaller
Bash
Étape2:
Comme avant de créer un dossier et d’y enregistrer le script python. Par exemple, nous avons créé un nom de dossier exe_app et y avons enregistré mon script python nommé app.py.
Étape3:
Ouvrez un terminal dans le même dossier où notre script python est enregistré, tapez la commande suivante et appuyez sur Entrée.
pyinstaller --onefile app.py
Bash
Sortir:
Étape4:
After running the command you can see that more files and folders are created in the root folder. There you can see folder name dist in that you can find the file name app.
vous pouvez lancer le fichier d’application en utilisant le commun suivant dans le terminal dans le même répertoire.
Merci de votre aide,
Cordialement
Hors ligne
#7 Le 05/06/2025, à 07:14
- MPython Alaplancha
Re : Compiler un script Python pour avoir un executable ubuntu
Comme je l'ai dis précédemment, il te faut utiliser pip install dans un environnement virtuel (comme venv). Ce n'était pas le cas il y a quelques années, mais son usage est rendu obligatoire maintenant par nos systèmes .
# Debian12 Mate
Hors ligne