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

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

Open
3 tasks done
ThmX opened this issue Jan 21, 2021 · 12 comments
Open
3 tasks done
Labels
area/scripts Related tool.poetry.scripts kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@ThmX
Copy link

ThmX commented Jan 21, 2021

  • 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
@ThmX ThmX added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jan 21, 2021
@sziem
Copy link

sziem commented Jan 29, 2021

I have encountered the same error, but found another workaround. I put the script i wanted to run in a subfolder (such as src). For example, poetry run script.py did not work, but poetry run src/script.py did.

I have also noticed that the same error occurs on my system, if I just run
poetry run --help, which according to poetry help run is supposed to work.

@dephekt
Copy link

dephekt commented Apr 3, 2021

I started having this issue today (seemingly randomly, Poetry was working fine a few days ago).

None of the above workarounds have helped. It's breaking every poetry project I have, not just a specific one.

If I do this, everything (besides poetry run) works fine:

source ~/.cache/pypoetry/virtualenvs/virustotal-4DyFcNxD-py3.8/bin/activate
python run.py

If I give an absolute path or relative path to the script, that actually works, e.g. both of these work:

poetry run /home/dephekt/virustotal/run.py
poetry run ./run.py

To get some visibility, I added a print in the os package on L600 just before the try/except clause for the call to exec_func() and see that it's looking in poetry's bin directory for my script, which obviously is not going to be there:

$ poetry run run.py --help
b'/home/dephekt/.cache/pypoetry/virtualenvs/virustotal-4DyFcNxD-py3.8/bin/run.py' ['run.py', '--help']
b'/home/dephekt/bin/run.py' ['run.py', '--help']
b'/usr/local/bin/run.py' ['run.py', '--help']
b'/home/dephekt/.local/bin/run.py' ['run.py', '--help']
b'/home/dephekt/.poetry/bin/run.py' ['run.py', '--help']
b'/home/dephekt/.local/bin/run.py' ['run.py', '--help']
b'/home/dephekt/bin/run.py' ['run.py', '--help']
b'/usr/local/sbin/run.py' ['run.py', '--help']
b'/usr/local/bin/run.py' ['run.py', '--help']
b'/usr/sbin/run.py' ['run.py', '--help']
b'/usr/bin/run.py' ['run.py', '--help']
b'/sbin/run.py' ['run.py', '--help']
b'/bin/run.py' ['run.py', '--help']
b'/usr/games/run.py' ['run.py', '--help']
b'/usr/local/games/run.py' ['run.py', '--help']
b'/snap/bin/run.py' ['run.py', '--help']

  FileNotFoundError

  [Errno 2] No such file or directory

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

It doesn't seem to be looking in the project directory when looking for run.py.

@iotanbo
Copy link

iotanbo commented May 19, 2021

Tried poetry on Ubuntu20.04, same problem. After installing it pyenv stopped working as intended.
Before:

python --version 
# Python 3.8.5
python3.9 --version 
# Python 3.9.5

After:

python --version
# Python 3.8.5
python3 --version
# Python 3.8.5
python3.9 --version
# Command 'python3.9' not found, did you mean: ...
which python
# /usr/bin/python

@iotanbo
Copy link

iotanbo commented May 19, 2021

I fixed the pyenv issue, but running poetry run -h yields following result:

$ poetry run -h

  FileNotFoundError

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

  at ~/.pyenv/versions/3.8.6/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

My PATH variable looks as follows:

/home/name/.pyenv/plugins/pyenv-virtualenv/shims:/home/name/.local/bin:/home/name/.pyenv/plugins/pyenv-virtualenv/shims:/home/name/.pyenv/shims:/home/name/.pyenv/bin:/home/name/.cargo/bin:/home/name/.local/bin:/home/name/.pyenv/shims:/home/name/.pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

@iotanbo
Copy link

iotanbo commented 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.

@epogrebnyak
Copy link

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 = 

@rustymagnet3000
Copy link

poetry run -vvv main

should that be?

poetry run python -vvv main

@DishaDudhal
Copy link

DishaDudhal commented Apr 21, 2022

Facing dvc issue with following: Note that I have already exported the path variable in my .bashrc file

dd$dd:~ poetry run dvc init --subdir

  FileNotFoundError

  [Errno 2] No such file or directory: b'/home/dd/.local/bin/dvc'

  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

@jelc53
Copy link

jelc53 commented Jul 18, 2022

@ThmX Can you provide more details for how to implement your suggested workaround?

@vparmeland
Copy link

Up ;)

@wagnerluis1982
Copy link
Contributor

wagnerluis1982 commented Jan 17, 2023

I just noticed in the issue description that is not following the CI recommendations to use poetry.

What ringed alarms to me is that you're installing poetry in the global python lib, not in some isolated environment (provided by venv, pipx or official installer).

I believe if you follow, you're not going to have the issue.

Link: https://python-poetry.org/docs/#ci-recommendations

@ThmX
Copy link
Author

ThmX commented Apr 4, 2023

Hoj, apologies for the delay in my answer. To be fully honest, I stopped using poetry since some time as we had too many open issues with cross-developement, decided to go with something smaller and closer to pip.

Anyway, I still wanted to rebase my PR but the code base seems to have changed a lot since then.

Haven't tried if the issue is stop open. I am

If someone has the time and will, you can base it on my commit ThmX@3d00f05

@finswimmer finswimmer added the area/scripts Related tool.poetry.scripts label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/scripts Related tool.poetry.scripts kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.