19

I've been trying to modify the default Python compiler/run command in Geany.

Some searching indicated that I would need to modify `/usr/share/geany/filetypes.python's last two lines as follows

#compiler=python -m py_compile "%f"
#run_cmd=python "%f"
compiler=python3 -c "import py_compile; py_compile.compile('%f')"
run_cmd=python3 "%f"

After restarting Geany however, Build -> Set Build Commands still shows the old commands and attemping to run a py3 script causes errors.

frlan
  • 6,950
  • 3
  • 31
  • 72
user3817250
  • 1,003
  • 4
  • 14
  • 27

3 Answers3

32

Add '3' to the end of "python" on the Build->Set Build Commands menu, as mentioned above.

Under Python commands, you should see:

  1. Compile python -m py_compile "%...

Add '3' to the end of python here

  1. Compile python3 -m py_compile "%...

enter image description here

  • It seems enough to change the `execute commands` and not the `compile` section init the geany setting as `python` can be executed/interpreted without compiling. – Timo Sep 02 '20 at 07:36
  • 1
    @Timo But the question asks about making python3 the default for both compiling and running. It would be a peculiar choice to want one version for compiling and a different for interpreting, so changing them both in a consistent way makes sense. Even if you don't think you need to compile any Python code *now*, keeping the settings consistent ensures you won't end up with weirdly confusing errors in the future if your needs change. – JBentley Feb 26 '23 at 20:40
15

First at all: Don't change the global configuration for something like this, as this will change default behaviour for all system users and might lead into confusion.

The changes inside file /usr/share/geany/filetypes.python will be overwritten in changes done inside your home on ~/.config/geany/filedefs/filetypes.python.

When using the menu Build->Set Build Commands it will be saved also there. In fact, there is no need to update the file manually, but via the menu. This will also have the advantage, changes will be visible without restarting Geany.

frlan
  • 6,950
  • 3
  • 31
  • 72
  • 2
    I thought it seemed strange to change it globally but that was all that popped up in my searches. Will the `Build->Set Build Commands` change the python default? My intent is to somewhat abandon python2.7 so I don't want to change the build commands for each file I'm working on. – user3817250 Mar 18 '15 at 14:37
  • It will not change what /usr/bin/env is using, but what you can call from Geany's build menu. There are different sections. Changing on Python section will add/change/delete the entry for all Python files in Geany. You could also add entries for Python2 and Python3 if you like. Just add a new line – frlan Mar 18 '15 at 14:49
0

For Linux:
Goto > Build > Set Build Commands In the Python Commands Edit the Command text box as:
python3 -m py_compile "%f"
In the Execute Commands Edit the Command as:
python3 "%f"

Geany Python3 Configuration

In the same way You can configure Geany for Python2 simply remove the '3' as: In the Python Commands Edit the Command text box as:
python -m py_compile "%f"
In the Execute Commands Edit the Command as:
python "%f"

You can also configure for specific python versions like Python3.7 simply replace the version number in the Set Build Commmands like: python3.7 -m py_compile "%f" in Commands and python3.7 "%f" in Execute

For Windows:
Goto > Build > Set Build Commands In the Python Commands Edit the Command text box as:
python -m py_compile "%f"
In the Execute Commands Edit the Command as(If you are using python3.7 and python is installed in C drive, otherwise browse to where Python is installed and replace it with the path, if path variable is not set):
C:\Python37\python "%f"

If you have python set in path variable, then this will work:
python "%f"

Saptarshi das
  • 379
  • 3
  • 6