Terminator crashes on startup if Python 3.x is default Python interpreter

Bug #1721991 reported by Christian Haudum
26
This bug affects 5 people
Affects Status Importance Assigned to Milestone
Terminator
Fix Released
High
Unassigned

Bug Description

I've set Python 3.6 as default Python interpreter. This will cause the startup script `/usr/bin/terminator` to fail due to wrong shebang.

```
$ terminator
  File "/usr/bin/terminator", line 124
    except (KeyError,ValueError), ex:
                                ^
SyntaxError: invalid syntax
```

Changing it from `#!/usr/bin/python` to `#!/usr/bin/env python2` would use the correct Python version even if Python 3 is default.

System information:

```
$ terminator --version
terminator 1.91
$ uname -a
Linux dba 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u3 (2017-08-06) x86_64 GNU/Linux

i3 desktop
```

Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

According to lp:1621156 this should be fixed... isn't it?

Revision history for this message
Christian Haudum (christian-haudum) wrote :

@Egmont So it was a Ubuntu packaging issue? I'm using Debian, though.

Revision history for this message
Stephen Boddy (stephen-j-boddy) wrote :

It's not an Ubuntu packaging thing. 1.91 should contain the fix (in fact I think 1.90 may even contain it.) I'm taking a stab that you are on stretch (by the deb9u3 in your uname output). I've checked the debian packages, and I see no sign of a patch that would revert the fix in lp:1621156 that Egmont mentions. I can't see how you have a 1.91 version without the python version specced in the shebang line. Did your package come from the central debian repo, or are you trying to use 3rd party packages?

Changed in terminator:
status: New → Incomplete
Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

On Ubuntu Artful beta's termiantor_1.91-1 package, /usr/bin/terminix starts with "#!/usr/bin/python".

Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

/usr/bin/terminator I mean... I'm getting confused by all these terminal emulators :-D

Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

Ditto with Fedora Rawhide's package. Neither seems to have any releavnt patch or build step.

Does maybe "setup.py install" alter the shebang like from the correct value to an incorrect one?

Revision history for this message
Christian Haudum (christian-haudum) wrote :

@Stephen Correct, I'm on stretch, but with testing repos (buster) enabled. terminator is installed via the central debian repo:

```
$ apt-cache showpkg terminator
Package: terminator
Versions:
1.91-1 (/var/lib/apt/lists/deb.debian.org_debian_dists_buster_main_binary-amd64_Packages) (/var/lib/dpkg/status)
 Description Language:
                 File: /var/lib/apt/lists/deb.debian.org_debian_dists_buster_main_binary-amd64_Packages
                  MD5: d70de009f48ea4b4f00e62329adb4f61
 Description Language: en
                 File: /var/lib/apt/lists/deb.debian.org_debian_dists_buster_main_i18n_Translation-en
                  MD5: d70de009f48ea4b4f00e62329adb4f61

Reverse Depends:
Dependencies:
1.91-1 - python-cairo (0 (null)) python-dbus (0 (null)) python-gi (0 (null)) python-gi-cairo (0 (null)) python-psutil (0 (null)) gir1.2-glib-2.0 (0 (null)) gir1.2-gtk-3.0 (0 (null)) gir1.2-pango-1.0 (0 (null)) gir1.2-vte-2.91 (0 (null)) python:any (2 2.7.5-5~) gir1.2-keybinder-3.0 (0 (null)) gir1.2-notify-0.7 (0 (null)) xdg-utils (0 (null))
Provides:
1.91-1 - x-terminal-emulator (= )
Reverse Provides:
```

Revision history for this message
Christian Haudum (christian-haudum) wrote :

@Egmont Your assumption with `setup.py install` modifying the shebang may be correct: https://stackoverflow.com/a/1530808

Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

In the source tree, terminator begins with "#!/usr/bin/env python2".

Running "./setup.py build" prints these (among many lines):

running build_scripts
creating build/scripts-2.7
copying and adjusting terminator -> build/scripts-2.7
copying and adjusting remotinator -> build/scripts-2.7

Those "adjusting"s are truly suspicious.

The resulting files under build/scripts-2.7/terminator begin with "#!/usr/bin/python2" on my computer (and later installed as such upon a "./setup.py install"). This probably depends on the build context and I guess might be simply "#!/usr/bin/python" when that's the only python version available, which is probably the case in Debian's, Red Hat's etc. build systems.

Indeed seems that setup.py, probably indirectly, buried somewhere in the distutils python modules, mangles the header in ways it shouldn't.

Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

Glazing through the answers and comments in that stackoverflow thread, it seems kinda reasonable for a build system to figure out the location of the interpreter and hardcode it (traditional autoconf/automake does plenty of such things too). The only thing they forget about is if distros offer multiple setups to their users, including each of python2 and python3 being available or not independently from each other, and if both are available, toggling where the /usr/bin/python symlink points to. Their approach fails here big time.

Most of that stackoverflow thread dates back to 2009. Perhaps python folks have come up with a proper solution to this problem. I don't know, I'm not really a python guy.

Revision history for this message
Stephen Boddy (stephen-j-boddy) wrote :

All I can say is Ugh! Slightly more confusing is that the setup.py *also* has python2 in the shebang. So doesn't that mean when it runs it uses the python2 binary?... Or is something forcing the setup.py to run with python3? Looks like a solution might be that the setup.py command changes from:
./setup.py install --record=install-files.txt
to:
./setup.py install --record=install-files.txt --executable="/usr/bin/env python2"

In terminator.spec (rpms) line 35 from:
%{__python} setup.py install -O1 --skip-build --root %{buildroot}
to:
%{__python} setup.py install -O1 --skip-build --root %{buildroot} --executable="/usr/bin/env python2"

In debian/rules line 8 (override_dh_auto_install) somewhere below add a line:
    --executable="/usr/bin/env python2" \

Changed in terminator:
status: Incomplete → Triaged
importance: Undecided → High
Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

There's a suggestion in the stackoverflow thread to install as data files rather than script.

The problem with the
  ./setup.py install --record=install-files.txt --executable="/usr/bin/env python2"
approach is that distros probably won't update their build rules just because you change something in INSTALL.

Plus, it's better if what distros do matches what people do "manually", e.g. you during development, and you won't type that --executable=blah every time :-)

So if reasonably possible, I think it's better if "./setup.py (build|install)" is fixed to work correctly. If it's not reasonably doable (without terrible hacks) then that's a different story.

Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

... or actually... I honestly don't know how much attention distros pay to the *.spec and debian/rules files shipped in the package. Maybe they do. (But also let's forget about the non-rpm/deb based ones.)

Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

let's *not* forget...

Revision history for this message
K4YT3X (k4yt3x) wrote :

Can someone please change the default shebang?
It's annoying cuz my default python interpreter is anaconda3

Revision history for this message
KurtB (kurt-tool) wrote :

This just hit me this morning. The quick and dirty hack
to get me back to work was to set the interpreter
on line 1 to:

#!/usr/bin/python2

I'm sure it's a bunch of work to get it going on py3. But,
well, 2.x stops getting support in 2020. If I had the time,
I'd help with the rewrite. But, unfortunately, time is one
thing I don't have a lot of.

Revision history for this message
Roman Kovtyukh (hellodeargrandma) wrote :
Revision history for this message
Mick (mbristol) wrote :

I had the same issue , using
Linux tomasim-desktop 4.18.0-25-generic #26-Ubuntu SMP Mon Jun 24 09:32:08 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
and terminator.
The issue came after I played with python 2.7 and python3.6 updates.
I switched the default python with
sudo update-alternatives --config python

note if you only have python3, then you can add python2 to the config with
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
with the ending "1" being the priority of choice.

Note I also had problems upgrading ubuntu due to python3 broken link, and had to force the link again to python2 with
https://askubuntu.com/questions/448926/how-to-fix-python-installation-is-corrupted

Revision history for this message
SteveSong (stephen-song) wrote :

Amazed that this is still a thing. KurtB's suggestion #16 seems like a reasonable workaround for the time being.

Revision history for this message
Markus Frosch (lazyfrosch) wrote :

Python 3 is now supported with 1.92:
https://github.com/gnome-terminator/terminator/releases

Changed in terminator:
status: Triaged → Fix Released
Revision history for this message
Asha Choudhary (asha2411) wrote :

1. sudo nano /usr/bin/terminator
2. Change #!/usr/bin/python to #!/usr/bin/python2.

Worked for me

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.