For some reason, I couldn't get it to work by just setting Exec=python3 %f, it kept giving me an end of file exception whenever the program tried to get input. It opens a separate terminal window which is pretty annoying.It doesn't work with scripts that have a space in their name.It's a pretty good workaround but I have found 2 problems with it: Now when you double click, it should run the script from the terminal. Then go to nautilus, right click on the script, go to Properties → Open With and select Run Python Script, the "Application" we just created. The difference is when you open it, it runs a new instance of the terminal line with the command: python3 %f echo "$(tput setaf 1)Program terminated.\nPress enter to exit.$(tput sgr 0)" read', which runs the script ( %f is apparently the file's path), then pauses on exit. desktop file of python interpreter itself. Paste the following into it: Įxec=gnome-terminal - /bin/bash -c 'python3 %f echo "$(tput setaf 1)Program terminated.\nPress enter to exit.$(tput sgr 0)" read' This should open up a terminal window, with Python running. Go to ~/.local/share/applications, create a new. Start Menu > Python (command line) OR Start Menu > Python > Python (command line). I have found a workaround if you don't want to bother with setting your script as an executable, adding comments to your code or selecting to run from the terminal every time you run it. In addition, if you have command line parameters, such as sys.argv in the script, you can't set them unless you have terminal window open. If you want the script to do something without seeing console output - use Run option. Prefer using Run in Terminal option if you want to see the code. If your script prints output to console, it will need to have terminal window, or alternatively use GUI dialogs such as zenity. If you are not using code that will be specific to python version - just use #!/usr/bin/env python Note on the script output: In case you are using python3 you could use either #!/usr/bin/python3 or #!/usr/bin/env python3 for portability. The very first line is called shebang line and must start with #! whatever comes next is the name of the interpreter that will read your code. In terminal you can do chmod +x /path/to/script.py and in GUI, right click on the file and alter its Properties -> Permissions Finally, make sure your file itself actually has executable permissions set.You need to open file manager, go to Edit -> Preferences -> Behavior, and select what to do with executable files In your case your very first line in the code must be #!/usr/bin/env python3 A script must have #! line telling the OS which interpreter to use.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |