python-3.xbashubuntu

Alias python to python3 in /bin/sh


Context

I'm using a package involving makefiles. Those makefiles send python commands to the terminal via /bin/sh (SHELL = /bin/sh in Makefile.common), the commands are always python some_script.py .... So for the sake of this question, let's assume I have to stick to /bin/sh.

The issue

python-is-python3 is installed:

axel@axel-ThinkPad-X250:~$ sudo apt install python-is-python3
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python-is-python3 is already the newest version (3.9.2-2).
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

python is an alias for python3 in ~/.bash_aliases as well as in ~/.profile (alias python='python3') and is functional in /bin/bash:

axel@axel-ThinkPad-X250:~$ /bin/bash
axel@axel-ThinkPad-X250:~$ python3
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
axel@axel-ThinkPad-X250:~$ python
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

But not in /bin/sh:

axel@axel-ThinkPad-X250:~$ /bin/sh
$ python3
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
$ python
/bin/sh: 2: python: not found
$ 

How can I get /bin/sh to understand that python is python3?


Solution

  • So it turns out that after creating a virtual environment with pip, python was found in /bin/sh. Stubborn me.