2

I have python3 installed on Ubuntu 20.04, and I have an application that needs python 2.7 installed. After installation of python 2.7 it looks like python cannot be found

 /usr/bin/python: bad interpreter: No such file or directory

which python, which python2 and which python3 do not return any results

Here's the content of /usr/bin:

root@ip-10-10-10-201:/home/ubuntu# ls -alh /usr/bin/pyt*
lrwxrwxrwx 1 root root    9 Mar 13  2020 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3.5M Aug  4 11:16 /usr/bin/python2.7
lrwxrwxrwx 1 root root    9 Mar 13  2020 /usr/bin/python3 -> python3.8
lrwxrwxrwx 1 root root   16 Mar 13  2020 /usr/bin/python3-config -> python3.8-config
-rwxr-xr-x 1 root root 5.3M Jul 28 12:59 /usr/bin/python3.8
lrwxrwxrwx 1 root root   33 Jul 28 12:59 /usr/bin/python3.8-config -> x86_64-linux-gnu-python3.8-config

I'm not sure how to get this working, if I need both pythons (2.7 and 3.8) to be working. Should I change the #!/usr/bin/python in the scripts that require phyton2 to #!/usr/bin/python2 ?

Will appreciate your help. Happy holidays!

igalsc
  • 85
  • 1
  • 1
  • 10
  • Start a new shell or reloading your profile may do it `source ~/.bash_profile` – ti7 Dec 22 '20 at 18:30
  • Do you see a file named exactly `/usr/bin/python` in this output from `ls`? In order to use the correct interpreter, you should specify a path to the _existing_ executable. Thus, you can use `/usr/bin/python2` or `/usr/bin/python2.7`. The shebang normally looks like `#!/usr/bin/env python`. – ForceBru Dec 22 '20 at 18:31
  • Does this answer your question? [: bad interpreter: No such file or directory in python](https://stackoverflow.com/questions/16757349/bad-interpreter-no-such-file-or-directory-in-python) – ti7 Dec 22 '20 at 18:33
  • Relevant: https://askubuntu.com/questions/1296790/python-is-python3-package-in-ubuntu-20-04-what-is-it-and-what-does-it-actually To get `python`, you have to explicitly choose between `python-is-python2` or `python-is-python3`. – chepner Dec 22 '20 at 18:35
  • @ti7 thanks, but it didn't work, and no, the link is not helpful – igalsc Dec 22 '20 at 18:38
  • @ForceBru thank you, changing `/usr/bin/python` to `/usr/bin/python2` seem working – igalsc Dec 22 '20 at 18:41
  • @ti7 the ubuntu link does explain it, thank you – igalsc Dec 22 '20 at 18:43
  • 2
    Keep in mind, though, that just because you link `/usr/bin/python` to one or the other, that doesn't mean it's *correct* for any arbitrary script that specifies `/usr/bin/python`. It's probably better to update the script to be explicitly. – chepner Dec 22 '20 at 18:46
  • @chepner that's exactly what I commented - changing /usr/bin/python to /usr/bin/python2 in the scripts seem working – igalsc Dec 23 '20 at 16:25

1 Answers1

2

As suggested by @ForceBru, changing the scripts from /usr/bin/python to /usr/bin/python2 seems to work.

This is due to the fact that Ubuntu Python packages are always coming as python2 and python3, not python.

mmBs
  • 8,421
  • 6
  • 38
  • 46
igalsc
  • 85
  • 1
  • 1
  • 10