Repository: python-poetry/poetry

Issue:
Poetry 1.5 fails to install dependencies
<!--
    Hi there! Thank you for submitting a bug report!

    Before you submit your issue, please review and follow the instructions at
    https://python-poetry.org/docs/contributing/#reporting-bugs. Fully fill out the template below; insufficient
    information or bad reproduction instructions will impair the ability of others to help you.
-->

<!-- All the below information must be provided for others to understand and help with your issue. -->
- **Poetry version**: 1.5
- **Python version**: 3.10
- **OS version and name**:  Ubuntu 20.04

<!-- All the below steps should be completed before submitting your issue. Checked checkbox should look like this: [x] -->
- [X ] I am on the [latest](https://github.com/python-poetry/poetry/releases/latest) stable Poetry version, installed using a recommended method.
- [ X] I have searched the [issues](https://github.com/python-poetry/poetry/issues) of this repo and believe that this is not a duplicate.
- [X ] I have consulted the [FAQ](https://python-poetry.org/docs/faq/) and [blog](https://python-poetry.org/blog/) for any relevant entries or release notes.
- [ X] If an exception occurs when executing a command, I executed it again in debug mode (`-vvv` option) and have included the output below.

## Issue
<!-- Now feel free to write your issue, and please be as descriptive as possible! Make sure to include detailed reproduction steps. -->
<!-- Thanks again 🙌 ❤ -->

When running `Poetry install` with the latest version (1.5) that was just released, I am getting `No such file or directory 'python'`.

The exact same project etc works fine with version 1.4.2.



Discussion:
obviously poetry 1.5.0 works fine for lots of us (including the pipelines).  You've provided no means to reproduce what you are seeing.

This is unactionable.  
I was able to recreate it with a very simple pyproject.toml file

```
[tool.poetry]
name = "test"
# this version is not used directly
# to get the latest version run git describe --tags --abbrev=0
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "~3.9"
click = "^8.0.4"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
```

The error I am seeing after adding verbose is

```
  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,
```

The reason for this is probably due to the fact I don't have `python` command defined on the Docker image I am using however I do have the command `python3`.
I can obviously work around it and have `python` defined using a simlink or something similar, however this was working fine in version 1.4.2. I did not see anything about it in the release notes and not sure if this was intentional.
so far as I know this hasn't changed, poetry has always assumed that there's a `python` in the environment.  cf #7348 for instance
I'd add that if you have a repro with a dockerfile, please share it.  No need to keep dribbling out the clues, just show us!
Same issue here with the `1.5` upgrade on a docker image based on Debian, running `apt-get install -y python-is-python3` fixed the issue!
sharing a way to reproduce this would be more useful than announcing that you are hitting it, please
(more evidence that this is not new: #6371)
@dimbleby I have done more investigating. I believe this error only happens when following environment variable is set:

POETRY_VIRTUALENVS_IN_PROJECT=true


Here is a pyproject.toml file I have used:

```
[tool.poetry]
name = "test"
# this version is not used directly
# to get the latest version run git describe --tags --abbrev=0
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "~3.10"
click = "^8.0.4"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
```

With the following Dockerfile

```
FROM ubuntu

RUN apt update

RUN apt install -y python3 curl vim

ADD pyproject.toml /

ENV POETRY_VIRTUALENVS_IN_PROJECT=true
ENV PATH="/root/.local/bin:${PATH}"

# installing using version 1.4.2 - this will work
RUN curl -sSL https://install.python-poetry.org | python3 - --version 1.4.2
RUN poetry install --verbose

RUN rm -rf .venv

# Remove 1.4.2 version
RUN curl -sSL https://install.python-poetry.org | python3 - --uninstall

# installing using version 1.5
RUN curl -sSL https://install.python-poetry.org | python3 -
RUN poetry install --verbose
```

Please run the following command (I am running it on mac):

`docker build -t python -f Dockerfile --no-cache .`

What you should see that the instructions in the file which operate on Poetry version 1.4.2 passes correctly. However, when you reach the last command in the Dockerfile which uses 1.5 that should fail with the error I provided before.

Hope this helps to understand the root cause.

Resolving patch:
diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py
--- a/src/poetry/utils/env.py
+++ b/src/poetry/utils/env.py
@@ -695,7 +695,7 @@ def get(self, reload: bool = False) -> Env:
 
         if not in_venv or env is not None:
             # Checking if a local virtualenv exists
-            if self.use_in_project_venv():
+            if self.in_project_venv_exists():
                 venv = self.in_project_venv
 
                 return VirtualEnv(venv)
@@ -733,7 +733,7 @@ def list(self, name: str | None = None) -> list[VirtualEnv]:
         venv_path = self._poetry.config.virtualenvs_path
         env_list = [VirtualEnv(p) for p in sorted(venv_path.glob(f"{venv_name}-py*"))]
 
-        if self.use_in_project_venv():
+        if self.in_project_venv_exists():
             venv = self.in_project_venv
             env_list.insert(0, VirtualEnv(venv))
         return env_list
@@ -852,6 +852,14 @@ def use_in_project_venv(self) -> bool:
         in_project: bool | None = self._poetry.config.get("virtualenvs.in-project")
         if in_project is not None:
             return in_project
+
+        return self.in_project_venv.is_dir()
+
+    def in_project_venv_exists(self) -> bool:
+        in_project: bool | None = self._poetry.config.get("virtualenvs.in-project")
+        if in_project is False:
+            return False
+
         return self.in_project_venv.is_dir()
 
     def create_venv(


Test patch: