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

[Errno 2] No such file or directory: 'python' on almost all poetry commands #4542

Closed
3 tasks done
dfontenot opened this issue Sep 22, 2021 · 14 comments
Closed
3 tasks done
Labels
kind/bug Something isn't working as expected

Comments

@dfontenot
Copy link

dfontenot commented Sep 22, 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).

Issue

Running into an issue in which I cannot run many Poetry commands in my project (e.g. poetry update, poetry shell, etc.). Tried in both zsh and bash. I get the error [Errno 2] No such file or directory: 'python'. I initially set up this project with the default settings, but I've since changed virtualenvs.create and virtualenvs.in-project to be true. Since this change I get these errors. Deleting the .venv/ directory in the project directory does not fix the issue.

Here's my current ~/.config/pypoetry/config.toml

[virtualenvs]
create = true
in-project = true

Output of poetry config --list (if that helps):

cache-dir = "/home/david/snap/alacritty/common/.cache/pypoetry"
experimental.new-installer = true
installer.parallel = true
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.path = "{cache-dir}/virtualenvs"  # /home/david/snap/alacritty/common/.cache/pypoetry/virtualenvs

I've found that if I completely comment out my ~/.config/pypoetry/config.toml file, I am then able to run poetry shell, which it appears to be installing in the default cache-dir directory. However, I would like to have my virtualenvs in the individual projects.

Output of poetry shell -vvv:

  Stack trace:

  14  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/console_application.py:131 in run
       129│             parsed_args = resolved_command.args
       130│
     → 131│             status_code = command.handle(parsed_args, io)
       132│         except KeyboardInterrupt:
       133│             status_code = 1

  13  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/api/command/command.py:120 in handle
       118│     def handle(self, args, io):  # type: (Args, IO) -> int
       119│         try:
     → 120│             status_code = self._do_handle(args, io)
       121│         except KeyboardInterrupt:
       122│             if io.is_debug():

  12  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/api/command/command.py:163 in _do_handle
       161│         if self._dispatcher and self._dispatcher.has_listeners(PRE_HANDLE):
       162│             event = PreHandleEvent(args, io, self)
     → 163│             self._dispatcher.dispatch(PRE_HANDLE, event)
       164│
       165│             if event.is_handled():

  11  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/api/event/event_dispatcher.py:22 in dispatch
        20│
        21│         if listeners:
     →  22│             self._do_dispatch(listeners, event_name, event)
        23│
        24│         return event

  10  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/api/event/event_dispatcher.py:89 in _do_dispatch
        87│                 break
        88│
     →  89│             listener(event, event_name, self)
        90│
        91│     def _sort_listeners(self, event_name):  # type: (str) -> None

   9  ~/.poetry/lib/poetry/console/config/application_config.py:119 in set_env
       117│
       118│         env_manager = EnvManager(poetry)
     → 119│         env = env_manager.create_venv(io)
       120│
       121│         if env.is_venv() and io.is_verbose():

   8  ~/.poetry/lib/poetry/utils/env.py:659 in create_venv
        657│
        658│         cwd = self._poetry.file.parent
     →  659│         env = self.get(reload=True)
        660│
        661│         if not env.is_sane():

   7  ~/.poetry/lib/poetry/utils/env.py:531 in get
        529│             base_prefix = self.get_base_prefix()
        530│
     →  531│         return VirtualEnv(prefix, base_prefix)
        532│
        533│     def list(self, name=None):  # type: (Optional[str]) -> List[VirtualEnv]

   6  ~/.poetry/lib/poetry/utils/env.py:1361 in __init__
       1359│         if base is None:
       1360│             self._base = Path(
     → 1361│                 self.run(self._executable, "-", input_=GET_BASE_PREFIX).strip()
       1362│             )
       1363│

   5  ~/.poetry/lib/poetry/utils/env.py:1140 in run
       1138│         bin = self._bin(bin)
       1139│         cmd = [bin] + list(args)
     → 1140│         return self._run(cmd, **kwargs)
       1141│
       1142│     def run_python(self, *args, **kwargs):

   4  ~/.poetry/lib/poetry/utils/env.py:1440 in _run
       1438│     def _run(self, cmd, **kwargs):
       1439│         kwargs["env"] = self.get_temp_environ(environ=kwargs.get("env"))
     → 1440│         return super(VirtualEnv, self)._run(cmd, **kwargs)
       1441│
       1442│     def get_temp_environ(

   3  ~/.poetry/lib/poetry/utils/env.py:1165 in _run
       1163│
       1164│             if input_:
     → 1165│                 output = subprocess.run(
       1166│                     cmd,
       1167│                     stdout=subprocess.PIPE,

   2  ~/.poetry/lib/poetry/utils/_compat.py:200 in run
       198│             kwargs["stdin"] = PIPE
       199│
     → 200│         process = Popen(*popenargs, **kwargs)
       201│         try:
       202│             process.__enter__()  # No-Op really... illustrate "with in 2.4"

   1  /usr/lib/python3.8/subprocess.py:858 in __init__
        856│                             encoding=encoding, errors=errors)
        857│
     →  858│             self._execute_child(args, executable, preexec_fn, close_fds,
        859│                                 pass_fds, cwd, env,
        860│                                 startupinfo, creationflags, shell,

  FileNotFoundError

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

  at /usr/lib/python3.8/subprocess.py:1704 in _execute_child
      1700│                     else:
      1701│                         err_filename = orig_executable
      1702│                     if errno_num != 0:
      1703│                         err_msg = os.strerror(errno_num)
    → 1704│                     raise child_exception_type(errno_num, err_msg, err_filename)
      1705│                 raise child_exception_type(err_msg)
      1706│
      1707│
      1708│         def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
@dfontenot dfontenot added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Sep 22, 2021
@Cilyan
Copy link

Cilyan commented Mar 15, 2022

This is due to https://github.com/python-poetry/poetry/blob/master/src/poetry/utils/env.py#L1135 that forces the interpreter to be python while by default it is python3 on ubuntu. The interpreter is supposed to be modified and corrected here https://github.com/python-poetry/poetry/blob/master/src/poetry/utils/env.py#L1187 but it fails. Anyway, it is strange that poetry tries to use an interpreter that is possible not the right one (e.g. when using conda/pipenv with a different version) and I don't know why it doesn't use sys.executable at least as a candidate.

As a workaround, you can symlink /usr/bin/python to /usr/bin/python3, or install the package python-is-python3 (which wasn't available on 20.04 but is available on more recent releases).

@haoxins
Copy link

haoxins commented Apr 21, 2022

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

Installing the latest version solved this issue.

@robsonpeixoto
Copy link

robsonpeixoto commented Jun 14, 2022

I'm have the same problem here:

❯ poetry env use /usr/local/opt/[email protected]/bin/python3

  FileNotFoundError

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

  at /usr/local/Cellar/[email protected]/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py:1842 in _execute_child
      1838│                     else:
      1839│                         err_filename = orig_executable
      1840│                     if errno_num != 0:
      1841│                         err_msg = os.strerror(errno_num)
    → 1842│                     raise child_exception_type(errno_num, err_msg, err_filename)
      1843│                 raise child_exception_type(err_msg)
      1844│ 
      1845│ 
      1846│         def _handle_exitstatus(self, sts,

❯ /usr/local/opt/[email protected]/bin/python3.7 -c "import sys; print('.'.join([str(s) for s in sys.version_info[:3]]))"
3.7.13

❯ poetry --version
Poetry version 1.1.13

@Teemu
Copy link

Teemu commented Jul 12, 2022

Removing the cache helped for me:

rm -rf ~/Library/Caches/pypoetry

@zrko
Copy link

zrko commented Jul 12, 2022

Teenu's comment about removing the cache on a Mac worked after an OS upgrade.

@abn
Copy link
Member

abn commented Jul 14, 2022

Can folks impacted by this issue on Debian try the following?

  1. Remove any existing virtual environment.
  2. Set the environment variable DEB_PYTHON_INSTALL_LAYOUT='deb'

@jelc53
Copy link

jelc53 commented Jul 18, 2022

Same issue for me. Trying some of the workarounds suggested in the comments now.

  | 
  |   FileNotFoundError
  | 
  |   [Errno 2] No such file or directory: 'python'
  | 
  |   at /usr/lib/python3.9/subprocess.py:1821 in _execute_child
  |       1817│                     else:
  |       1818│                         err_filename = orig_executable
  |       1819│                     if errno_num != 0:
  |       1820│                         err_msg = os.strerror(errno_num)
  |     → 1821│                     raise child_exception_type(errno_num, err_msg, err_filename)
  |       1822│                 raise child_exception_type(err_msg)
  |       1823│ 
  |       1824│ 
  |       1825│         def _handle_exitstatus(self, sts,
 exited with code 1

@ejkitchen
Copy link

Just installed poetry on Windows with WSL/Ubuntu and my problem was nothing worked. Could not even launch poetry.

For some reason this worked: ~/.local/bin/poetry which then made me realize it was a path issue.

Then found this on StackOverflow:

export PATH="$HOME/.local/bin:$PATH"

solved my problem

@mnogokotin
Copy link

It helps me: sudo apt install python-is-python3

@neersighted
Copy link
Member

There are a bunch of wildly different things tracked here -- most being local system/config issues. For the Python 3.10 on modern Debian/Ubuntu issue, the new issue is #6371.

@mkniewallner mkniewallner removed the status/triage This issue needs to be triaged label Sep 18, 2022
@GeeWee
Copy link

GeeWee commented Oct 17, 2022

For anyone who might come here later - I had the same issue, and clearing out my temporary project files such as .venv resolved the error. I think it came after upgrading my version of python.

@bouchardi
Copy link

Closing my terminal and relaunching solved the issue for me!

@bn0
Copy link

bn0 commented Nov 14, 2022

For me, I'd only installed python3 (with homebrew), so no python existed in $PATH. Adding a python symlink to python3 worked.

sudo ln -s /opt/homebrew/bin/python3 /opt/homebrew/bin/python

@neersighted
Copy link
Member

I'm going to lock this issue as it's just generating noise: the only issue related to Poetry (and not even Poetry, but in fact our dependency virtualenv and Debian patches) is linked, and all the rest is local configuration issues.

@python-poetry python-poetry locked as off-topic and limited conversation to collaborators Nov 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests