Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.0.0b4] poetry run fails with FileNotFoundError #1567

Closed
3 tasks done
MrGreenTea opened this issue Nov 11, 2019 · 29 comments · Fixed by #5243
Closed
3 tasks done

[1.0.0b4] poetry run fails with FileNotFoundError #1567

MrGreenTea opened this issue Nov 11, 2019 · 29 comments · Fixed by #5243
Labels
area/cli Related to the command line area/error-handling Bad error messages/insufficient error handling kind/bug Something isn't working as expected

Comments

@MrGreenTea
Copy link
Contributor

MrGreenTea commented Nov 11, 2019

  • 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.

@MrGreenTea MrGreenTea added the kind/bug Something isn't working as expected label Nov 11, 2019
@hoefling
Copy link
Contributor

Me also getting this error with the 1.0.0b4. Using double dashes is broken in the latest beta, e.g. poetry run -- pytest -svx --lf ends with the FileNotFoundError message.

@taketarouex
Copy link

taketarouex commented Jan 1, 2020

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

@JavierL1
Copy link

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

Can you give a little bit more feedback on how did you resolve the issue? You removed the poetry install command from execution?

@taketarouex
Copy link

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

@JavierL1
Copy link

I just solved my problem. I used for reference this issue #1198.
In my case, I have a project that uses a CLI interface implemented with click. So in order to run a command using poetry, first I had to register the group of commands as a poetry script, just like it's described here.
I hope it helps you!

@kiudee
Copy link

kiudee commented Aug 3, 2020

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.

@dector
Copy link

dector commented Aug 17, 2020

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

@technillogue
Copy link

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

@finswimmer finswimmer added the area/error-handling Bad error messages/insufficient error handling label Dec 26, 2020
@mattwelke
Copy link

mattwelke commented Jan 12, 2021

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

@rourich
Copy link

rourich commented Feb 5, 2021

Me also getting this error with the 1.0.0b4. Using double dashes is broken in the latest beta, e.g. poetry run -- pytest -svx --lf ends with the FileNotFoundError message.

were you able to circumvent this problem?

@Nathaniel-Rink
Copy link

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

@joker234
Copy link

joker234 commented Mar 16, 2021

I have a similar error:

$ poetry run --no-ansi echo "hello"

  FileNotFoundError

  [Errno 2] No such file or directory

  at /usr/local/lib/python3.8/os.py:601 in _execvpe
       597│         path_list = map(fsencode, path_list)
       598│     for dir in path_list:
       599│         fullname = path.join(dir, file)
       600│         try:
    →  601│             exec_func(fullname, *argrest)
       602│         except (FileNotFoundError, NotADirectoryError) as e:
       603│             last_exc = e
       604│         except OSError as e:
       605│             last_exc = e

or

$ poetry --no-ansi run echo "hello"
USAGE
  poetry help [<command1>] ... [<commandN>]

ARGUMENTS
  <command>              The command name

GLOBAL OPTIONS
  -h (--help)            Display this help message
  -q (--quiet)           Do not output any message
  -v (--verbose)         Increase the verbosity of messages: "-v" for normal output, "-vv" for more verbose output and "-vvv" for debug
  -V (--version)         Display this application version
  --ansi                 Force ANSI output
  --no-ansi              Disable ANSI output
  -n (--no-interaction)  Do not ask any interactive question

vs.

$ poetry run echo "hello"
hello

According to the help, I can use --no-ansi and --no-interaction with every poetry command. Where am I supposed to put them? The help isn't clear on that terms.

$ poetry help run
USAGE
  poetry run <args1> ... [<argsN>]

ARGUMENTS
  <args>                 The command and arguments/options to run.

GLOBAL OPTIONS
  -h (--help)            Display this help message
  -q (--quiet)           Do not output any message
  -v (--verbose)         Increase the verbosity of messages: "-v" for normal output, "-vv" for more verbose output and "-vvv" for debug
  -V (--version)         Display this application version
  --ansi                 Force ANSI output
  --no-ansi              Disable ANSI output
  -n (--no-interaction)  Do not ask any interactive question

Edit: some information on my system:

  • Tested within a python:3.8 docker container
  • poetry installed via pip install --no-cache-dir poetry

@NelsonAPenn
Copy link

I get this error if I haven't properly added / installed a package within poetry. But the error is especially baffling in my case, because the directory it is trying to read from shouldn't be python related at all:

Below is some slightly censored output (just the file path censored) for if I run poetry run pytest without having first installed / added pytest.

poetry run pytest

  FileNotFoundError

  [Errno 2] No such file or directory: b'/path/to/my/godot/installation/godot-3.2.3/pytest'

  at /usr/lib/python3.8/os.py:601 in _execvpe
       597│         path_list = map(fsencode, path_list)
       598│     for dir in path_list:
       599│         fullname = path.join(dir, file)
       600│         try:
    →  601│             exec_func(fullname, *argrest)
       602│         except (FileNotFoundError, NotADirectoryError) as e:
       603│             last_exc = e
       604│         except OSError as e:
       605│             last_exc = e

I have no idea why poetry wants to look in the folder in which I installed godot, but it does, every time. Similarly:

 poetry run "the answer to life, the universe and everything"

  FileNotFoundError

  [Errno 2] No such file or directory: b'/path/to/my/godot/installation/godot-3.2.3/the answer to life, the universe and everything'

  at /usr/lib/python3.8/os.py:601 in _execvpe
       597│         path_list = map(fsencode, path_list)
       598│     for dir in path_list:
       599│         fullname = path.join(dir, file)
       600│         try:
    →  601│             exec_func(fullname, *argrest)
       602│         except (FileNotFoundError, NotADirectoryError) as e:
       603│             last_exc = e
       604│         except OSError as e:
       605│             last_exc = e

System: ubuntu 20.04
Poetry version: 1.1.6

@gstravinskaite
Copy link

I have the same issue as above, it tries to look to the Golang binaries to run Python program.

@comalice
Copy link

comalice commented Jan 26, 2022

I have this same issue but it is looking for Perl binaries...

root@alatham <path to poetry project> (<virtualenv-name>) # poetry run

  FileNotFoundError

  [Errno 2] No such file or directory: b'/usr/bin/core_perl/run'

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

Note that I'm running from WSL2 on Arch Linux.

@elyobo
Copy link

elyobo commented Feb 4, 2022

Had the same problem, poetry install resolved it (even though nothing had changed 🤷‍♂️)

@NelsonAPenn
Copy link

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.

@branchvincent
Copy link
Member

branchvincent commented Feb 27, 2022

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

@pkoch
Copy link

pkoch commented Mar 18, 2022

Just got bit by this. In my case, I'd forgotten to run poetry install before poetry run pytest.

@1player
Copy link

1player commented Jul 6, 2022

Still having this issue in version 1.1.3

% poetry -V
Poetry version 1.1.13
% poetry run

  FileNotFoundError

  [Errno 2] No such file or directory: b'/usr/bin/core_perl/run'

  at /usr/lib/python3.10/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

@pkoch
Copy link

pkoch commented Jul 6, 2022

@1player that's not really a lot to work with. That might very well be something specific to your usage.

Can you make a repo with the minimum reproducible case for your problem?

@1player
Copy link

1player commented Jul 6, 2022

I literally just created a new repo with poetry init and ran poetry run. Running on Arch Linux.

@pkoch
Copy link

pkoch commented Jul 6, 2022

Indeed. Here's how I repro'ed it:

cd $(mktemp -d)

cat - > Dockerfile <<EOF
FROM archlinux

RUN pacman -Syyu --noconfirm python \
 && mkdir /code
WORKDIR /code
RUN (curl -sSL https://install.python-poetry.org | python3 -) \
 && /root/.local/bin/poetry init -n
EOF

# This takes a little while, give it time.
docker run --rm $(docker build -q .) /root/.local/bin/poetry run

@dimbleby
Copy link
Contributor

dimbleby commented Jul 6, 2022

On more recent versions of poetry you will see this:

$ poetry run

Not enough arguments (missing: "args")

which is a more helpful error message

@pkoch
Copy link

pkoch commented Jul 6, 2022

@dimbleby Can you name what's the version that starts happening? I've repo'ed @1player's problem with Poetry version 1.1.13.

@dimbleby
Copy link
Contributor

dimbleby commented Jul 6, 2022

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

@pkoch
Copy link

pkoch commented Jul 6, 2022

Using curl -sSL https://install.python-poetry.org | python3 - --version "1.2.0b2", I do see that new error. 👌

@NourKired
Copy link

you have to add on you're pyproject.toml, this script:
example:
[tool.poetry.scripts]
converter-image-text = "converter_image_text.main:cli"

Copy link

github-actions bot commented Mar 1, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/cli Related to the command line area/error-handling Bad error messages/insufficient error handling kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.