1

I have a Makefile that contains these two lines

run: sim
    @python run.py $(INPUT)

When I tried to run make run, I got the error message saying python is not found. I soon realized that was because I had only python3, so I added the line

alias python=python3

to the file ~/.bashrc and ~/.profile separately. That is, I tried to fix the problem twice by adding this alias to two different files. However, even after I sourced the file and could run python in the terminal, make run still gave the same error.

However, the problem is fixed after I install a package by running apt install python-is-python3. Although I don't have this problem anymore, I do not know how it was fixed. Isn't python-is-python3 just creating a symlink from /usr/bin/python to python3? Is it any different from the alias approach I tried?

1
  • @guiverc Ubuntu 20.04.1 LTS
    – ark
    Oct 9, 2020 at 8:33

1 Answer 1

1

Isn't python-is-python3 just creating a symlink from /usr/bin/python to python3?

Yes it is.

Is it any different from the alias approach I tried?

Yes it is - bash aliases are only expanded in an interactive bash shell. The shell used by make is /bin/sh by default, and is not interactive. Symbolic links are handled at the filesystem level and are hence independent of the shell.

For further discussion about shells and Makefiles, see How can I use Bash syntax in Makefile targets?

2
  • But I remember ~/.profile would be used for non-interactive shells as well. Actually it is specify here. Does it mean the shell used by Makfile does not come with --login option?
    – ark
    Oct 9, 2020 at 12:35
  • ~/.profile would be read by a /bin/sh login shell; but even if make executed commands in a login shell (it doesn't, AFAIK), the fact that it would do so non-interactively would disable aliases. Oct 9, 2020 at 12:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .