-2

I am learning python and I have made a weather app with Tkinter and a weather api. I want to be able to run the 'main.py' file, which makes all of the class calls for the app, from my desktop so I don't have to navigate to the project folder and run the app from the console. Would I have to make some sort of bash script or would I have to make the program an executable? Or is there something else I could do?

I have tried py2exe and it has not worked for me so far.

Edit: I decided to create a batch script and it worked, thank you for your suggestions :D

3 Answers3

1

alternatives to py2exe you can try :

Let me know how it goes!

0

As @art cut sky says in a previous version of his answer, a shortcut may also work. In that case there is no need to create a shell script.

The rest of the answer assumes you use Linux or something similar. macOS and Windows need different instructions. (Shell scripts are not partical for Windows, and the desktop works differently on macOS.)

A shell script like this should work:

#!/bin/sh --
cd "$HOME/foo/bar" &&
    exec python main.py "$@"

Change foo/bar above to the actual directory pathname conaining main.py.

If you use virtualenv, write the script differently: it should contain all commands which you type to the Bash prompt. If it doesn't work, ask a separate question, and include all the details.

Save the above script file as ~/Desktop/runmain.sh, and make it executable: chmod +x ~/Desktop/runmain.sh.

pts
  • 80,836
  • 20
  • 110
  • 183
0

2 suggestions

  1. Create a batch script: - More reading in the following link https://www.howtogeek.com/263177/how-to-write-a-batch-script-on-windows/

     python path\to\your\program.py
    
  2. Convert your program to an executable: You can use a tool like PyInstaller to convert your Python program to an executable file. https://pyinstaller.org/en/stable/index.html