question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

poetry run raises FileNotFoundError without any more information (workaround found)

See original GitHub issue
  • 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).
  • OS version and name: docker alpine:3.13
  • Poetry version: 1.1.4
  • Link of a Gist with the contents of your pyproject.toml file: vanilla project from poetry init with a main.py and the following scripts section:
[tool.poetry.scripts]
main = "main:main"

Issue

Using the following Dockerfile as base image on our build pipeline.

FROM alpine:3.13
RUN apk add --update --no-cache python3 python3-dev py3-pip py3-pandas py3-numpy-dev hdf5-dev
RUN pip install poetry
RUN poetry config virtualenvs.create false

poetry run main crashes with the following error:

/workdir # poetry init
/workdir # poetry run -vvv main

  FileNotFoundError

  [Errno 2] No such file or directory

  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

Note that enabling or disabling virtualenvs.create has the same effect.

Long story short, I’ve been able to work around the issue and hope this might help others. Here is what did the trick:

/workdir # ln -s /usr/bin/python3 /usr/bin/python

It seems that poetry run is expecting python to be found in the PATH (https://github.com/python-poetry/poetry/blob/master/poetry/console/commands/run.py#L40) on contrary to poetry which is directly using python3:

/workdir # head -1 /usr/bin/poetry
#!/usr/bin/python3

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:11
  • Comments:10

github_iconTop GitHub Comments

12reactions
epogrebnyakcommented, Sep 10, 2021

Same issue here of Ubuntu:

root@LAPTOP-E0HT1CM9:/mnt/c/Users/epogr/Documents/GitHub/rides-blueprint# poetry run --help

  FileNotFoundError

  [Errno 2] No such file or directory: b'/snap/bin/--help'

  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 = 
2reactions
iotanbocommented, May 19, 2021

Finally I fixed my problem: it was the bad entry in the pyproject.toml:

[tool.poetry.scripts]
poetry-test = "poetry_test.console:main"

Here poetry-test is the script to be executed like poetry run poetry-test, poetry_test is the package name, console.py is a python file inside the package, and main is the function inside console.py. Sorry for the newbie’s comments, I’ve just got acquainted with poetry 😃. Hopefully this will help someone else.

Read more comments on GitHub >

github_iconTop Results From Across the Web

poetry run worker.py | FileNotFound [Errno 2] No such file or ...
poetry run means "run the following command in the venv managed by poetry". So the correct way of using it in your case...
Read more >
poetry install [errno 2] no such file or directory: 'python'
Running poetry fails with /usr/bin/env: 'python': No such file or directory ... But before few minutes I found the solution for this error....
Read more >
How to fix FileNotFoundError Errno 2 no such file or directory
The error FileNotFoundError Errno 2 no such file or directory occurs when Python cannot find the specified file in the current directory.
Read more >
Python GDAL package missing header file when installing via ...
selimnairb's answer is close but you wont have the headers unless you've installed libgdal-dev: sudo apt-get install libgdal-dev.
Read more >
How to Publish an Open-Source Python Package to PyPI
In this step-by-step tutorial, you'll learn how to create a Python package for your project and how to publish it to PyPI, the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found