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

All poetry commands fail with [Errno 2] No such file or directory: 'python' #6841

Closed
4 tasks done
edufresne opened this issue Oct 19, 2022 · 23 comments
Closed
4 tasks done
Labels
kind/question User questions (candidates for conversion to discussion)

Comments

@edufresne
Copy link

Environment Information

  • Poetry version: Poetry (version 1.2.2)
  • Python version: Python 3.10.8
  • OS version and name: MacOS 12.6
  • pyproject.toml:
[tool.poetry]
name = "my-project"
version = "1.0.0"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
Flask = "^2.2.2"
weasyprint = "^56.1"
gunicorn = "^20.1.0"
Werkzeug = "^2.2.2"

[tool.poetry.group.dev.dependencies]
black = "^22.8.0"
pytest = "^7.1.3"
coverage = "^6.4.4"
isort = "^5.10.1"
pip-audit = "^2.4.4"
autoflake = "^1.6.1"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.black]
line-length = 120
include = '\.pyi?$'
known_first_party = ["app", "tests"]
exclude='(\.eggs|\.git|\.idea|\.pytest_cache|venv|build|dist|logs)'

[tool.pytest.ini_options]
log_cli = true

[tool.coverage.run]
branch = true
source = ["app"]
command_line = "-m pytest tests --junitxml reports/test.xml --durations 0 --verbose"

[tool.coverage.xml]
output = "reports/coverage.xml"

[tool.coverage.html]
directory = "reports/coverage_html"

[tool.autoflake]
recursive = true
remove-all-unused-imports = true
remove-unused-variables = true
ignore-init-module-imports = true
exclude = ".git,.idea,.pytest_cache,__pycache__,logs,static,test/reports,venv"
  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate. Related ticket but with no solution found and for different OS
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Stack Trace

Loading configuration file /Users/ericdufresne/Library/Preferences/pypoetry/config.toml
Loading configuration file /Users/ericdufresne/Library/Preferences/pypoetry/auth.toml

  Stack trace:

  17  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cleo/application.py:329 in run
       327│ 
       328│             try:
     → 329│                 exit_code = self._run(io)
       330│             except Exception as e:
       331│                 if not self._catch_exceptions:

  16  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/poetry/console/application.py:185 in _run
       183│         self._load_plugins(io)
       184│ 
     → 185│         exit_code: int = super()._run(io)
       186│         return exit_code
       187│ 

  15  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cleo/application.py:423 in _run
       421│             io.input.set_stream(stream)
       422│ 
     → 423│         exit_code = self._run_command(command, io)
       424│         self._running_command = None
       425│ 

  14  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cleo/application.py:465 in _run_command
       463│ 
       464│         if error is not None:
     → 465│             raise error
       466│ 
       467│         return event.exit_code

  13  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cleo/application.py:446 in _run_command
       444│ 
       445│         try:
     → 446│             self._event_dispatcher.dispatch(event, COMMAND)
       447│ 
       448│             if event.command_should_run():

  12  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cleo/events/event_dispatcher.py:23 in dispatch
        21│ 
        22│         if listeners:
     →  23│             self._do_dispatch(listeners, event_name, event)
        24│ 
        25│         return event

  11  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cleo/events/event_dispatcher.py:84 in _do_dispatch
        82│                 break
        83│ 
     →  84│             listener(event, event_name, self)
        85│ 
        86│     def _sort_listeners(self, event_name: str) -> None:

  10  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/poetry/console/application.py:294 in configure_env
       292│ 
       293│         env_manager = EnvManager(poetry)
     → 294│         env = env_manager.create_venv(io)
       295│ 
       296│         if env.is_venv() and io.is_verbose():

   9  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/poetry/utils/env.py:833 in create_venv
        831│ 
        832│         cwd = self._poetry.file.parent
     →  833│         env = self.get(reload=True)
        834│ 
        835│         if not env.is_sane():

   8  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/poetry/utils/env.py:711 in get
        709│                 return self.get_system_env()
        710│ 
     →  711│             return VirtualEnv(venv)
        712│ 
        713│         if env_prefix is not None:

   7  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/poetry/utils/env.py:1652 in __init__
       1650│         # from inside the virtualenv.
       1651│         if base is None:
     → 1652│             output = self.run_python_script(GET_BASE_PREFIX)
       1653│             assert isinstance(output, str)
       1654│             self._base = Path(output.strip())

   6  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/poetry/utils/env.py:1438 in run_python_script
       1436│ 
       1437│     def run_python_script(self, content: str, **kwargs: Any) -> int | str:
     → 1438│         return self.run(self._executable, "-W", "ignore", "-", input_=content, **kwargs)
       1439│ 
       1440│     def _run(self, cmd: list[str], **kwargs: Any) -> int | str:

   5  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/poetry/utils/env.py:1430 in run
       1428│     def run(self, bin: str, *args: str, **kwargs: Any) -> str | int:
       1429│         cmd = self.get_command_from_bin(bin) + list(args)
     → 1430│         return self._run(cmd, **kwargs)
       1431│ 
       1432│     def run_pip(self, *args: str, **kwargs: Any) -> int | str:

   4  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/poetry/utils/env.py:1712 in _run
       1710│     def _run(self, cmd: list[str], **kwargs: Any) -> int | str:
       1711│         kwargs["env"] = self.get_temp_environ(environ=kwargs.get("env"))
     → 1712│         return super()._run(cmd, **kwargs)
       1713│ 
       1714│     def get_temp_environ(

   3  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/poetry/utils/env.py:1459 in _run
       1457│ 
       1458│             if input_:
     → 1459│                 output = subprocess.run(
       1460│                     command,
       1461│                     stdout=subprocess.PIPE,

   2  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py:503 in run
        501│         kwargs['stderr'] = PIPE
        502│ 
     →  503│     with Popen(*popenargs, **kwargs) as process:
        504│         try:
        505│             stdout, stderr = process.communicate(input, timeout=timeout)

   1  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py:971 in __init__
        969│                             encoding=encoding, errors=errors)
        970│ 
     →  971│             self._execute_child(args, executable, preexec_fn, close_fds,
        972│                                 pass_fds, cwd, env,
        973│                                 startupinfo, creationflags, shell,

  FileNotFoundError

  [Errno 2] No such file or directory: 'python'

  at /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py:1847 in _execute_child
      1843│                     else:
      1844│                         err_filename = orig_executable
      1845│                     if errno_num != 0:
      1846│                         err_msg = os.strerror(errno_num)
    → 1847│                     raise child_exception_type(errno_num, err_msg, err_filename)
      1848│                 raise child_exception_type(err_msg)
      1849│ 
      1850│ 
      1851│         def _handle_exitstatus(self, sts,

Extra Info

  • Python location /Library/Frameworks/Python.framework/Versions/3.10/bin/python3
  • Poetry location /Library/Frameworks/Python.framework/Versions/3.10/bin/poetry

Issue

Hello. I am trying to use Poetry for mac with Python 3.10. It was working before but I re-installed both Python and poetry and I can't seem to get it to work. I can run commands like poetry --version but commands such as poetry install poetry lock poetry show all faill with [Errno 2] No such file or directory: 'python' and the above stack trace on debug mode.

I have tried installing Poetry both with curl -sSL https://install.python-poetry.org | python3 - as well as the manual way with pip3 install poetry. My Python is installed via the regular Python.org .pkg installer for MacOS but I had it installed with homebrew before which also suffered from the same issue.

Thank you in advance for the help!

@edufresne edufresne added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Oct 19, 2022
@neersighted neersighted added kind/question User questions (candidates for conversion to discussion) and removed kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Oct 19, 2022
@neersighted
Copy link
Member

It looks like you have a broken virtual environment -- I'd suggest cleaning up with rm -rf .venv && poetry env remove --all. I suspect that the virtual env looks valid but has a broken symlink for the Python binary, based on the output (we're failing in env.py, during commands which rely on the environment existing and need to introspect it).

@edufresne
Copy link
Author

Where is .venv supposed to be located? It didn't exist in my project's directory and both of the commands:

poetry env list
poetry env remove --all

fail with the same command

@neersighted
Copy link
Member

neersighted commented Oct 19, 2022

.venv may exist if you set poetry config virtualenvs.in-project true. I was trying to provide a one-liner, but if poetry env remove is broken, you can instead do rm -rf $(poetry config virtualenvs.path)/* to blow away all of your Poetry environments.

Edit: Please ensure poetry config virtualenvs.path does in fact return a valid path before trying to use the rm -rf command. If it's empty you might end up with an attempt to remove your entire root partition.

@edufresne
Copy link
Author

That did the trick! Had to go in manually and delete the virtualenvs in the default virtualenv directory with your command . I then was able to set poetry config virtualenvs.in-project true and create my virtualenvs on the project level.

Thanks for your help!

@GyurkanM
Copy link

GyurkanM commented Jan 6, 2023

.venv may exist if you set poetry config virtualenvs.in-project true. I was trying to provide a one-liner, but if poetry env remove is broken, you can instead do rm -rf $(poetry config virtualenvs.path)/* to blow away all of your Poetry environments.

This command deleted my teammate's entire Ubuntu partition 😄

@diogobaltazar
Copy link

sudo apt install python-is-python3

@yrro
Copy link

yrro commented Jan 27, 2023

Seems like some part of poetry is trying to run python instead of referring to sys.executable...

Yup, in poetry.utils.env.GenericEnv, find_executables is grubbing around for hard coded executable names instead of using sys.executable.

(Seen here with Poetry 1.3.2)

@yrro
Copy link

yrro commented Feb 2, 2023

Hold on I didn't realise this issue is closed. I'll open a new one: #7456

@jove4015
Copy link

rm -rf $(poetry config virtualenvs.path)/*

To anyone else who comes here - do not run this. Totally borked my computer.

@GreatTyrion
Copy link

@jove4015 Thanks for your information.

@lcarlier
Copy link

sudo apt install python-is-python3

Life saver! Thank you!

@fmelihh
Copy link

fmelihh commented May 25, 2023

sudo apt install python-is-python3

It was very helpful for me. Thank you.

@samhaaf-pondurance
Copy link

The issue for me ended up being that I had an alias python="python3.11". Removed that and it worked again

@dbersan
Copy link

dbersan commented Jun 5, 2023

ON MAC what worked was reinstalling Poetry

curl -sSL https://install.python-poetry.org | python3 -

@sandipb
Copy link

sandipb commented Jul 19, 2023

ON MAC what worked was reinstalling Poetry

curl -sSL https://install.python-poetry.org | python3 -

or, if you use homebrew:

brew install pipx
pipx install poetry

@adekunleba
Copy link

For me, the issue was that I set prefer-active-python to true meanwhile, i only have the python3 command active so python command would not work. Setting this to false or linking python command to python3 will do the trick. This is the idea also of the command sudo apt install python-is-python3 suggested up.

@wicklander-bryant
Copy link

sudo apt install python-is-python3

In my case, I was attempting to run AutoGPT on ubuntu-22.04 with python 3.10 and was seeing the error mentioned in the original post. The fix was to simply run sudo apt install python-is-python3, thank you 🙏

@wedesoft
Copy link

wedesoft commented Nov 1, 2023

We did something like this (only we set POETRY_HOME to /etc/poetry). For some reason python was in a venv subdirectory:

export POETRY_HOME=/usr
curl -sSL https://install.python-poetry.org | python3 - --version 1.4.0
export PATH=$PATH:$POETRY_HOME/venv/bin

Poetry install then worked and found Python.

$POETRY_HOME/bin/poetry install

@cortadocodes
Copy link

I had this issue recently but only for one repository. I tried the solutions above but they didn't work for me. It turned out to be a caching issue and I ended up having to:

  1. Delete the entry in /Users/<user>/Library/Caches/pypoetry/virtualenvs/envs.toml for the repository I was working on
  2. Delete any previous virtualenvs for the repository in /Users/<user>/Library/Caches/pypoetry/virtualenvs

I worked out it was a caching issue by finding I could poetry install my package if I changed its name in pyproject.toml.

@e-b
Copy link

e-b commented Feb 23, 2024

.venv may exist if you set poetry config virtualenvs.in-project true. I was trying to provide a one-liner, but if poetry env remove is broken, you can instead do rm -rf $(poetry config virtualenvs.path)/* to blow away all of your Poetry environments.

I have removed all env as you recommended - no envs left, not in the Library/Caches and not in my project (I set config virtualenvs.in-project true), however the problem remains. Where can I fix this symlink to 'python'? Thanks for your help!

@yene
Copy link

yene commented Mar 5, 2024

After migrating my mac to ARM I fixed it with a symbolic link. Setting an alias in zsh was not enough.
ln -s /opt/homebrew/bin/python3 /opt/homebrew/bin/python

@redthing1
Copy link

After migrating my mac to ARM I fixed it with a symbolic link. Setting an alias in zsh was not enough. ln -s /opt/homebrew/bin/python3 /opt/homebrew/bin/python

This is the only thing that worked for me.

Copy link

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 Apr 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/question User questions (candidates for conversion to discussion)
Projects
None yet
Development

No branches or pull requests