r/learnpython • u/GoldEquivalent3597 • 3d ago
Creare app sul computer
Ciao a tutti, sto imparando a usare python, solitamente eseguo il codice dentro spider ma vorrei proprio creare delle app eseguibili dal desktop (ho windows)
5
Upvotes
2
u/AgitatedTumbleweed65 3d ago
Pyinstaller is one option, you package depencies and a version of python interpreter along with your code into and executable. but the executables are large and can be slow on start up. Other options are some python to compiled languages translators that then compile in that translateed language, for sure there is a number of those that exists.
Edit:typos
1
u/socal_nerdtastic 3d ago edited 3d ago
If you install python from the official python.org site, and install it with the default options, you can just doubleclick any .py file to run it. If your program has a graphical interface and you don't want the terminal to show up, rename the file with a .pyw extension. You can manage your venvs (if you are using them) with the shebang in the file.
Another option is to make a windows shortcut or bat file that points to your python executable and file. I made a small python program that helps with that: https://github.com/socal-nerdtastic/pyshortcut
Alternatively, you can use 'freezing' programs like PyInstaller to make executables from your python code. https://www.reddit.com/r/learnpython/wiki/faq/?screen_view_count=1#wiki_how_do_i_create_an_executable_from_my_python_code.3F
1
u/Agawell 3d ago
Run it from the command line or create a shortcut that runs it from the command line
1
u/Sufficient-Tale6131 2d ago
One gotcha since you're coming from Spyder: if you installed it through Anaconda, your packages live in the conda environment, so double clicking a .py file can launch a different Python that doesn't have them, and the window just flashes and closes.
Easiest fix is a small .bat file next to your script that calls the Anaconda python.exe directly with your script as the argument, plus a line with just pause at the end so you can read any error. You can find the right path by typing where python in the Anaconda Prompt. Same idea if you try PyInstaller later, run it from the Anaconda Prompt so it sees the right packages.