python-poetry / python-poetry/poetry

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

Open
#3,592 12 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/scripts kind/bug status/triage
Dominant language
Python
Stars
34.3k
Forks
2.5k
Avg merge
2d 19h
Merged PRs (30d)
30

Description

  • 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with poetry/console/commands/run.py and reproduce the command in the Alpine 3.13 Docker environment described in the issue. Check how poetry run resolves the configured script when only python3 is available, and use the existing traceback and workaround to define the expected behavior or error message.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.