Running poetry fails with /usr/bin/env: ‘python’: No such file or directory

Viewed 14183

I just installed poetry with the following install script

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3

However, when I execute poetry it fails with the following error

$ poetry
/usr/bin/env: ‘python’: No such file or directory

I recently upgraded to ubuntu 20.04, is this an issue with the upgrade or with poetry?

2 Answers

poetry is dependent on whatever python is and doesn't attempt to use a specific version of python unless otherwise specified.

The above issue will exist on ubuntu systems moving forward 20.04 onwards as python2.7 is deprecated and the python command does not map to python3.x

You'll find specifying an alias for python to python3 won't work ( unless, perhaps you specify this in your bashrc instead of any other shell run command file ) as poetry spins it's own shell to execute commands.

Install the following package instead

sudo apt install python-is-python3

It should be noted that you can install python2.7 if you want to and poetry should run fine.

Also an issue on some other Ubuntu versions/variants (Mint 19.3 here).

The python-is-python3 answer from arshbot is a good option, alternatively I found just tweaking the script that invokes poetry fixed it for me: A more delicate approach, but also more fragile in case the script gets updated (so overwritten) in future. So anyway here's that lightweight/fragile option:

Edit the script,

vi ~/.poetry/bin/poetry

(other editors are available etc) and change the top line:

#!/usr/bin/env python

becomes

#!/usr/bin/env python3

sorted!

This is only likely to be needed as a temporary workaround considering finswimmer's comment, from which it seems poetry will be more intelligent about using python3 in future in this situation.

Related