poetry: [1.0.0b4] poetry run fails with FileNotFoundError

  • I am on the latest Poetry version.

  • I have searched the issues of this repo and believe that this is not a duplicate.

  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option). poetry run -vvv does not change anything about the output

  • OS version and name: Linux x86_64 (Elementary OS)

  • Poetry version: 1.0.0b4

  • Link of a Gist with the contents of your pyproject.toml file: Link (generated with poetry new)

Issue

Running poetry run without additional argument fails with

[FileNotFoundError]
[Errno 2] No such file or directory

Executing poetry run pip list for example works fine. It’s just with either no argument or when the first argument is not found as an executable.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 22
  • Comments: 29 (4 by maintainers)

Most upvoted comments

I’m getting this error even after I run poetry install.

Steps to reproduce:

  • Create new Poetry project with poetry init.
  • Create file app.py with contents print('hello').
  • Run poetry run app.py.

Something I notice is that poetry can’t run my program but using python directly can:

poetry run app.py 

  FileNotFoundError

  [Errno 2] No such file or directory

  at ~/.pyenv/versions/3.9.1/lib/python3.9/os.py:607 in _execvpe
       603│         path_list = map(fsencode, path_list)
       604│     for dir in path_list:
       605│         fullname = path.join(dir, file)
       606│         try:
    →  607│             exec_func(fullname, *argrest)
       608│         except (FileNotFoundError, NotADirectoryError) as e:
       609│             last_exc = e
       610│         except OSError as e:
       611│             last_exc = e
python app.py 
hello

EDIT:

Oh wait, I’m just stupid. I misunderstood how to use the poetry run command. Checking the docs helped me:

poetry run python app.py
hello

it would be awfully nice if poetry told you to run poetry install or something instead of just FileNotFoundError

Same problem here using 1.0.10 on Ubuntu 20.04.

poetry run --help

results in

[FileNotFoundError]
[Errno 2] No such file or directory

while poetry run python or poetry run pip works.

Related to #2741.

I also getting this error after renaming the parent dir. And it resolved by removing .venv dir and executing poetry install

EDIT:

Oh wait, I’m just stupid. I misunderstood how to use the poetry run command. Checking the docs helped me:

poetry run python app.py
hello

This was immensely helpful. I’d misread the instructions too

no, I don’t know where this changed. Try with the latest beta 1.2.0b2.

On more recent versions of poetry you will see this:

$ poetry run

Not enough arguments (missing: "args")

which is a more helpful error message

I’m sorry. I was mistaken. I intended to say that I removed .venv dir, after that I executed poetry install and I resolved it

Some of the UX issues around run have already been fixed on master:

$ poetry --version
Poetry (version 1.2.0a2)
$ poetry run

Not enough arguments (missing: "args")
$ poetry run --help

Description:
  Runs a command in the appropriate environment.
...
$ poetry run -vvv echo test
Loading configuration file /Users/Branch/Library/Application Support/pypoetry/config.toml
Using virtualenv: /Users/Branch/Code/python-poetry/poetry/.venv
test

I’ve filed #5243 to address the remaining cryptic FileNotFoundError when an executable isn’t found

In terms of the error message, it is raised during the call to os.execvpe. The reason the directory in the message is so weird in every case is because it is always the last path in the system path.

I think that the output of poetry run <command> could be much improved if it were to produce the same output that would appear if you ran poetry shell followed by <command> in the subshell. Running a nonexist command within poetry shell returns (on Ubuntu 20.04)


Command 'aoeu' not found, did you mean:

  command 'aoeui' from deb aoeui (1.7+20160302.git4e5dee9-2)

Try: sudo apt install <deb name>

which is kind of result you’d expect in this situation. I’ve looked into this a little and am not sure on the implementation details, but will create a PR if I come up with something I’m satisfied with.

I have this issue too.

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.6 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.6 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
$ poetry --version
Poetry version 1.0.10

This doesn’t work:

$ poetry run "echo hello"
Poetry version [OSError]
[Errno 2] No such file or directory
$ poetry run --help
Poetry version [OSError]
[Errno 2] No such file or directory

This works:

$ poetry run echo hello
hello