My Python files opens in gedit instead of Python. Is there a way to fix this?
I have tried to allow them to execute in the properties setting, but that didn't work. I can open them in the terminal, but not in the "usual" way.
My Python files opens in gedit instead of Python. Is there a way to fix this?
I have tried to allow them to execute in the properties setting, but that didn't work. I can open them in the terminal, but not in the "usual" way.
There's two ways we could interpret this - you don't specify whether you want the script to be run by the Python interpreter, or if you want it to open the script in IDLE.
1. You want to execute the script.
While we can't execute the script directly from within Nautilus, we can create a .desktop file that will launch the script for you. Simply open up gedit, nano, or whatever editor you want and enter the following:
[Desktop Entry]
Type=Application
Exec=python /path/to/your/code.py
Icon=/path/to/icon # not necessary, just for looks
Name=Name of your script
Terminal=true # Tells the system to open it in a terminal
Save this somewhere. You can save anywhere, but if you want it accessible/launchable from the dash you'll need to save it in ~/.local/share/applications/
.
2. You want to open the script in IDLE
As far as I can tell, you can't actually open a Python script directly in IDLE. Strange, I know. Granted, I don't use IDLE that much (if at all), so it could just be the way my system is set up.
You can, however, create another .desktop file that will launch IDLE with your script.
[Desktop Entry]
Type=Application
Exec=idle-python3.4 /path/to/your/code.py
Icon=/path/to/icon # not necessary, just for looks
Name=Name of your script
You'll notice that the command is idle-python3.4
. This answer is assuming you are running Ubuntu 14.04 (default Python 3 installation is 3.4). However, if you have or use a different version, then you'll need to change this line to be the correct command for your IDLE version.
You'll also notice we dropped the Terminal=true
line the second time. This is because IDLE doesn't need to be launched from the terminal.