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

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!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 10
  • Comments: 22 (2 by maintainers)

Most upvoted comments

.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 😄

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).

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

sudo apt install python-is-python3

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

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

sudo apt install python-is-python3

Life saver! Thank you!

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.

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

ON MAC what worked was reinstalling Poetry

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

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.

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)