I am a beginner in programming (and in English) and I had to bring a USB key at school, because I had a homework to do. But I don't know how can I read a .py
file on my teacher's computer, because there's no Python on it.
So how can I do? Thank you if you try to help me.
PS: I use tkinter and pygame on my code
PS #2: you can help me in french, it can be easier.
PS #3: it s a good game console ! lmao
CodePudding user response:
To run python locally, you need Python on the computer or USB. But there are a lot of free online tools that allow you to run python. You can log in with a browser and run the program online (it might be a bit slow). It would be easier if you can use IPython in Jupyter notebooks to run your game. I once used https://cocalc.com/ for a different purpose.
CodePudding user response:
You need to convert the python file into an executable and then run it on another computer.
Open the default terminal and type pip install pyinstaller
Then, go to the location where your python file is there and type:
pyinstaller --onefile -w file_name.py
This will create a single file. If you don't want it, just remove the --onefile
flag.
The -w
flag removes the console window. You can remove the flag if you want the console to display.
Also, if you want an icon for the file, use --icon="path_to_icon.ico"
flag.
For more info: https://www.pyinstaller.org/
French Translation (by Google):
Vous devez convertir le fichier python en un exécutable, puis l'exécuter sur un autre ordinateur.
Ouvrez le terminal par défaut et tapez pip install pyinstaller
Ensuite, allez à l'emplacement où se trouve votre fichier python et tapez :
pyinstaller --onefile -w nom_fichier.py
Cela créera un seul fichier. Si vous ne le souhaitez pas, supprimez simplement le drapeau --onefile
.
Le drapeau -w
supprime la fenêtre de la console. Vous pouvez supprimer l'indicateur si vous souhaitez que la console s'affiche.
De plus, si vous voulez une icône pour le fichier, utilisez l'indicateur --icon="path_to_icon.ico"
.
Pour plus d'informations: https://www.pyinstaller.org/