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 followingscripts
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:
- Created 3 years ago
- Reactions:11
- Comments:10
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Same issue here of Ubuntu:
Finally I fixed my problem: it was the bad entry in the
pyproject.toml
:Here
poetry-test
is the script to be executed likepoetry run poetry-test
,poetry_test
is the package name,console.py
is a python file inside the package, andmain
is the function insideconsole.py
. Sorry for the newbie’s comments, I’ve just got acquainted withpoetry
😃. Hopefully this will help someone else.