poetry
poetry copied to clipboard
[Errno 2] No such file or directory: 'python' on almost all poetry commands
- [x] I am on the latest Poetry version.
- [x] I have searched the issues of this repo and believe that this is not a duplicate.
- [x] If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option).
- OS version and name: Ubuntu 20.04
- Poetry version: 1.1.10
- Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/dfontenot/bdaa7940af0a9bc72c41e91500072880#file-pyproject-toml
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,
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).
curl -sSL https://install.python-poetry.org | python3 -
Installing the latest version solved this issue.
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
Removing the cache helped for me:
rm -rf ~/Library/Caches/pypoetry
Teenu's comment about removing the cache on a Mac worked after an OS upgrade.
Can folks impacted by this issue on Debian try the following?
- Remove any existing virtual environment.
- Set the environment variable
DEB_PYTHON_INSTALL_LAYOUT='deb'
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
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
It helps me: sudo apt install python-is-python3
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.
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.
Closing my terminal and relaunching solved the issue for me!
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
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.