Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 340
arshbot Avatar asked May 20 '20 20:05

arshbot


People also ask

Can't execute Python No such file or directory?

The Python "FileNotFoundError: [Errno 2] No such file or directory" occurs when we try to open a file that doesn't exist in the specified location. To solve the error, move the file to the directory where the Python script is located if using a local path, or use an absolute path.

What version of Python does poetry use?

Poetry requires Python 2.7 or 3.5+. It is multi-platform and the goal is to make it work equally well on Windows, Linux and OSX. Python 2.7 and 3.5 will no longer be supported in the next feature release (1.2). You should consider updating your Python version to a supported one.

What does usr bin env mean?

As we mentioned earlier,#!/usr/bin/env bash is also a shebang line used in script files to execute commands with the Bash shell. It uses the env command to display the environment variables present in the system and then execute commands with the defined interpreter.

How do you upgrade a poem?

Updating poetry to the latest stable version is as simple as calling the self update command. If you want to install prerelease versions, you can use the --preview option. And finally, if you want to install a specific version you can pass it as an argument to self update .


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.

like image 91
arshbot Avatar answered Nov 03 '22 01:11

arshbot


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.

like image 26
Andrew Richards Avatar answered Nov 02 '22 23:11

Andrew Richards