Running poetry fails with /usr/bin/env: ‘python’: No such file or directory
Question:
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?
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.
FOR MAC USERS
Run this:
ls -l /usr/local/bin/python*
You should get something like this:
lrwxr-xr-x 1 irfan admin 34 Nov 11 16:32 /usr/local/bin/python3 -> ../Cellar/python/3.7.5/bin/python3
lrwxr-xr-x 1 irfan admin 41 Nov 11 16:32 /usr/local/bin/python3-config -> ../Cellar/python/3.7.5/bin/python3-config
lrwxr-xr-x 1 irfan admin 36 Nov 11 16:32 /usr/local/bin/python3.7 -> ../Cellar/python/3.7.5/bin/python3.7
lrwxr-xr-x 1 irfan admin 43 Nov 11 16:32 /usr/local/bin/python3.7-config -> ../Cellar/python/3.7.5/bin/python3.7-config
lrwxr-xr-x 1 irfan admin 37 Nov 11 16:32 /usr/local/bin/python3.7m -> ../Cellar/python/3.7.5/bin/python3.7m
lrwxr-xr-x 1 irfan admin 44 Nov 11 16:32 /usr/local/bin/python3.7m-config -> ../Cellar/python/3.7.5/bin/python3.7m-config
Change the default python symlink to the version you want to use from above.
Note that, we only need to choose the one that ends with python3.*. Please avoid using the ones’ that end with config or python3.*m or python3.*m-config.
Run this:
ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python
Check if it’s working:
python --version # Should output Python 3.7.5
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?
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.
FOR MAC USERS
Run this:
ls -l /usr/local/bin/python*
You should get something like this:
lrwxr-xr-x 1 irfan admin 34 Nov 11 16:32 /usr/local/bin/python3 -> ../Cellar/python/3.7.5/bin/python3
lrwxr-xr-x 1 irfan admin 41 Nov 11 16:32 /usr/local/bin/python3-config -> ../Cellar/python/3.7.5/bin/python3-config
lrwxr-xr-x 1 irfan admin 36 Nov 11 16:32 /usr/local/bin/python3.7 -> ../Cellar/python/3.7.5/bin/python3.7
lrwxr-xr-x 1 irfan admin 43 Nov 11 16:32 /usr/local/bin/python3.7-config -> ../Cellar/python/3.7.5/bin/python3.7-config
lrwxr-xr-x 1 irfan admin 37 Nov 11 16:32 /usr/local/bin/python3.7m -> ../Cellar/python/3.7.5/bin/python3.7m
lrwxr-xr-x 1 irfan admin 44 Nov 11 16:32 /usr/local/bin/python3.7m-config -> ../Cellar/python/3.7.5/bin/python3.7m-config
Change the default python symlink to the version you want to use from above.
Note that, we only need to choose the one that ends with python3.*. Please avoid using the ones’ that end with config or python3.*m or python3.*m-config.
Run this:
ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python
Check if it’s working:
python --version # Should output Python 3.7.5