Repository: pypa/pipenv

Issue:
pipenv sync --system fails on version 2023.7.1
### Issue description

Using new pipenv on my docker build fails (see logs below), while hard coding to previous version (`2023.6.26`) still works

### Expected result

Build step succeed:
```
Step 7/10 : RUN pipenv sync --system
 ---> Running in ae2759a184bd
Installing dependencies from Pipfile.lock (095195)...
All dependencies are now up-to-date!
Removing intermediate container ae2759a184bd
 ---> 58b0fa0107d0
```

### Actual result

```
Step 7/10 : RUN pipenv sync --system --verbose
 ---> Running in e5ef94abcd11
Traceback (most recent call last):
  File "/var/lang/bin/pipenv", line 8, in <module>
    sys.exit(cli())
  File "/var/lang/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/var/lang/lib/python3.8/site-packages/pipenv/cli/options.py", line 58, in main
    return super().main(*args, **kwargs, windows_expand_args=False)
  File "/var/lang/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/var/lang/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/var/lang/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/var/lang/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/var/lang/lib/python3.8/site-packages/pipenv/vendor/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/var/lang/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/var/lang/lib/python3.8/site-packages/pipenv/vendor/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/var/lang/lib/python3.8/site-packages/pipenv/cli/command.py", line 676, in sync
    retcode = do_sync(
  File "/var/lang/lib/python3.8/site-packages/pipenv/routines/install.py", line 364, in do_sync
    ensure_project(
  File "/var/lang/lib/python3.8/site-packages/pipenv/utils/project.py", line 82, in ensure_project
    os.environ["PIP_PYTHON_PATH"] = project.python
  File "/var/lang/lib/python3.8/site-packages/pipenv/project.py", line 1163, in python
    return project_python(self)
  File "/var/lang/lib/python3.8/site-packages/pipenv/utils/shell.py", line 404, in project_python
    python = project._which("python")
  File "/var/lang/lib/python3.8/site-packages/pipenv/project.py", line 1172, in _which
    raise RuntimeError("location not created nor specified")
RuntimeError: location not created nor specified
The command '/bin/sh -c pipenv sync --system --verbose' returned a non-zero code: 1
```

### Steps to replicate

```
$ cat Dockerfile 
FROM ubuntu:latest

ARG FUNCTION_DIR="/"

RUN apt update && apt install -y python3-pip
RUN pip3 install pipenv

# Setup Python environment
COPY ./Pipfile ./Pipfile.lock ${FUNCTION_DIR}
RUN pipenv --support
RUN pipenv sync --system --verbose


$ cat Pipfile
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
jsonmerge = "*"

[dev-packages]
mypy = "*"

[requires]
python_version = "3.8"
```

<details><summary>$ pipenv --support</summary>

Pipenv version: `'2023.7.1'`

Pipenv location: `'/usr/local/lib/python3.10/dist-packages/pipenv'`

Python location: `'/usr/bin/python3'`

OS Name: `'posix'`

User pip version: `'22.0.2'`

user Python installations found:


PEP 508 Information:

```
{'implementation_name': 'cpython',
 'implementation_version': '3.10.6',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '5.14.0-1056-oem',
 'platform_system': 'Linux',
 'platform_version': '#63-Ubuntu SMP Fri Dec 16 14:32:59 UTC 2022',
 'python_full_version': '3.10.6',
 'python_version': '3.10',
 'sys_platform': 'linux'}
```

System environment variables:

  - `HOSTNAME`
  - `HOME`
  - `PATH`
  - `FUNCTION_DIR`
  - `PWD`
  - `LC_CTYPE`
  - `PYTHONDONTWRITEBYTECODE`
  - `PIP_DISABLE_PIP_VERSION_CHECK`
  - `PYTHONFINDER_IGNORE_UNSUPPORTED`

Pipenv–specific environment variables:


Debug–specific environment variables:

  - `PATH`: `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin`
  - `PWD`: `/`


---------------------------

Contents of `Pipfile` ('/Pipfile'):
```toml
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
jsonmerge = "*"

[dev-packages]
mypy = "*"

[requires]
python_version = "3.8"


```


Contents of `Pipfile.lock` ('/Pipfile.lock'):

```json
{
    "_meta": {
        "hash": {
            "sha256": "729f81036905aae7dc69f82790b0cb9d87d67478e11e63f3f026e3316ff58d0d"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.8"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "attrs": {
            "hashes": [
                "sha256:1f28b4522cdc2fb4256ac1a020c78acf9cba2c6b461ccd2c126f3aa8e8335d04",
                "sha256:6279836d581513a26f1bf235f9acd333bc9115683f14f7e8fae46c98fc50e015"
            ],
            "version": "==23.1.0"
        },
        "importlib-resources": {
            "hashes": [
                "sha256:4be82589bf5c1d7999aedf2a45159d10cb3ca4f19b2271f8792bc8e6da7b22f6",
                "sha256:7b1deeebbf351c7578e09bf2f63fa2ce8b5ffec296e0d349139d43cca061a81a"
            ],
            "markers": "python_version < '3.9'",
            "version": "==5.12.0"
        },
        "jsonmerge": {
            "hashes": [
                "sha256:a2d1f80021c5c1d70a49e31f862b5f068f9db066080d8561e80654de74a3584d"
            ],
            "index": "pypi",
            "version": "==1.9.0"
        },
        "jsonschema": {
            "hashes": [
                "sha256:0f864437ab8b6076ba6707453ef8f98a6a0d512a80e93f8abdb676f737ecb60d",
                "sha256:a870ad254da1a8ca84b6a2905cac29d265f805acc57af304784962a2aa6508f6"
            ],
            "version": "==4.17.3"
        },
        "pkgutil-resolve-name": {
            "hashes": [
                "sha256:357d6c9e6a755653cfd78893817c0853af365dd51ec97f3d358a819373bbd174",
                "sha256:ca27cc078d25c5ad71a9de0a7a330146c4e014c2462d9af19c6b828280649c5e"
            ],
            "markers": "python_version < '3.9'",
            "version": "==1.3.10"
        },
        "pyrsistent": {
            "hashes": [
                "sha256:016ad1afadf318eb7911baa24b049909f7f3bb2c5b1ed7b6a8f21db21ea3faa8",
                "sha256:1a2994773706bbb4995c31a97bc94f1418314923bd1048c6d964837040376440",
                "sha256:20460ac0ea439a3e79caa1dbd560344b64ed75e85d8703943e0b66c2a6150e4a",
                "sha256:3311cb4237a341aa52ab8448c27e3a9931e2ee09561ad150ba94e4cfd3fc888c",
                "sha256:3a8cb235fa6d3fd7aae6a4f1429bbb1fec1577d978098da1252f0489937786f3",
                "sha256:3ab2204234c0ecd8b9368dbd6a53e83c3d4f3cab10ecaf6d0e772f456c442393",
                "sha256:42ac0b2f44607eb92ae88609eda931a4f0dfa03038c44c772e07f43e738bcac9",
                "sha256:49c32f216c17148695ca0e02a5c521e28a4ee6c5089f97e34fe24163113722da",
                "sha256:4b774f9288dda8d425adb6544e5903f1fb6c273ab3128a355c6b972b7df39dcf",
                "sha256:4c18264cb84b5e68e7085a43723f9e4c1fd1d935ab240ce02c0324a8e01ccb64",
                "sha256:5a474fb80f5e0d6c9394d8db0fc19e90fa540b82ee52dba7d246a7791712f74a",
                "sha256:64220c429e42a7150f4bfd280f6f4bb2850f95956bde93c6fda1b70507af6ef3",
                "sha256:878433581fc23e906d947a6814336eee031a00e6defba224234169ae3d3d6a98",
                "sha256:99abb85579e2165bd8522f0c0138864da97847875ecbd45f3e7e2af569bfc6f2",
                "sha256:a2471f3f8693101975b1ff85ffd19bb7ca7dd7c38f8a81701f67d6b4f97b87d8",
                "sha256:aeda827381f5e5d65cced3024126529ddc4289d944f75e090572c77ceb19adbf",
                "sha256:b735e538f74ec31378f5a1e3886a26d2ca6351106b4dfde376a26fc32a044edc",
                "sha256:c147257a92374fde8498491f53ffa8f4822cd70c0d85037e09028e478cababb7",
                "sha256:c4db1bd596fefd66b296a3d5d943c94f4fac5bcd13e99bffe2ba6a759d959a28",
                "sha256:c74bed51f9b41c48366a286395c67f4e894374306b197e62810e0fdaf2364da2",
                "sha256:c9bb60a40a0ab9aba40a59f68214eed5a29c6274c83b2cc206a359c4a89fa41b",
                "sha256:cc5d149f31706762c1f8bda2e8c4f8fead6e80312e3692619a75301d3dbb819a",
                "sha256:ccf0d6bd208f8111179f0c26fdf84ed7c3891982f2edaeae7422575f47e66b64",
                "sha256:e42296a09e83028b3476f7073fcb69ffebac0e66dbbfd1bd847d61f74db30f19",
                "sha256:e8f2b814a3dc6225964fa03d8582c6e0b6650d68a232df41e3cc1b66a5d2f8d1",
                "sha256:f0774bf48631f3a20471dd7c5989657b639fd2d285b861237ea9e82c36a415a9",
                "sha256:f0e7c4b2f77593871e918be000b96c8107da48444d57005b6a6bc61fb4331b2c"
            ],
            "version": "==0.19.3"
        },
        "zipp": {
            "hashes": [
                "sha256:112929ad649da941c23de50f356a2b5570c954b65150642bccdd66bf194d224b",
                "sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556"
            ],
            "markers": "python_version < '3.10'",
            "version": "==3.15.0"
        }
    },
    "develop": {
        "mypy": {
            "hashes": [
                "sha256:01fd2e9f85622d981fd9063bfaef1aed6e336eaacca00892cd2d82801ab7c042",
                "sha256:0dde1d180cd84f0624c5dcaaa89c89775550a675aff96b5848de78fb11adabcd",
                "sha256:141dedfdbfe8a04142881ff30ce6e6653c9685b354876b12e4fe6c78598b45e2",
                "sha256:16f0db5b641ba159eff72cff08edc3875f2b62b2fa2bc24f68c1e7a4e8232d01",
                "sha256:190b6bab0302cec4e9e6767d3eb66085aef2a1cc98fe04936d8a42ed2ba77bb7",
                "sha256:2460a58faeea905aeb1b9b36f5065f2dc9a9c6e4c992a6499a2360c6c74ceca3",
                "sha256:34a9239d5b3502c17f07fd7c0b2ae6b7dd7d7f6af35fbb5072c6208e76295816",
                "sha256:43b592511672017f5b1a483527fd2684347fdffc041c9ef53428c8dc530f79a3",
                "sha256:43d24f6437925ce50139a310a64b2ab048cb2d3694c84c71c3f2a1626d8101dc",
                "sha256:45d32cec14e7b97af848bddd97d85ea4f0db4d5a149ed9676caa4eb2f7402bb4",
                "sha256:470c969bb3f9a9efcedbadcd19a74ffb34a25f8e6b0e02dae7c0e71f8372f97b",
                "sha256:566e72b0cd6598503e48ea610e0052d1b8168e60a46e0bfd34b3acf2d57f96a8",
                "sha256:5703097c4936bbb9e9bce41478c8d08edd2865e177dc4c52be759f81ee4dd26c",
                "sha256:7549fbf655e5825d787bbc9ecf6028731973f78088fbca3a1f4145c39ef09462",
                "sha256:8207b7105829eca6f3d774f64a904190bb2231de91b8b186d21ffd98005f14a7",
                "sha256:8c4d8e89aa7de683e2056a581ce63c46a0c41e31bd2b6d34144e2c80f5ea53dc",
                "sha256:98324ec3ecf12296e6422939e54763faedbfcc502ea4a4c38502082711867258",
                "sha256:9bbcd9ab8ea1f2e1c8031c21445b511442cc45c89951e49bbf852cbb70755b1b",
                "sha256:9d40652cc4fe33871ad3338581dca3297ff5f2213d0df345bcfbde5162abf0c9",
                "sha256:a2746d69a8196698146a3dbe29104f9eb6a2a4d8a27878d92169a6c0b74435b6",
                "sha256:ae704dcfaa180ff7c4cfbad23e74321a2b774f92ca77fd94ce1049175a21c97f",
                "sha256:bfdca17c36ae01a21274a3c387a63aa1aafe72bff976522886869ef131b937f1",
                "sha256:c482e1246726616088532b5e964e39765b6d1520791348e6c9dc3af25b233828",
                "sha256:ca637024ca67ab24a7fd6f65d280572c3794665eaf5edcc7e90a866544076878",
                "sha256:e02d700ec8d9b1859790c0475df4e4092c7bf3272a4fd2c9f33d87fac4427b8f",
                "sha256:e5952d2d18b79f7dc25e62e014fe5a23eb1a3d2bc66318df8988a01b1a037c5b"
            ],
            "index": "pypi",
            "version": "==1.4.1"
        },
        "mypy-extensions": {
            "hashes": [
                "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d",
                "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"
            ],
            "version": "==1.0.0"
        },
        "tomli": {
            "hashes": [
                "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc",
                "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"
            ],
            "markers": "python_version < '3.11'",
            "version": "==2.0.1"
        },
        "typing-extensions": {
            "hashes": [
                "sha256:5d8c9dac95c27d20df12fb1d97b9793ab8b2af8a3a525e68c80e21060c161771",
                "sha256:935ccf31549830cda708b42289d44b6f74084d616a00be651601a4f968e77c82"
            ],
            "version": "==4.7.0"
        }
    }
}

```
</details>



Discussion:
same here
works fine with `pipenv==2023.6.26`
Same with:
`pipenv install --system --deploy --ignore-pipfile`

```
FROM python:3.9.1-alpine as base

ENV PYTHONDONTWRITEBYTECODE 1

RUN apk update \
    && apk add postgresql-dev gcc python3-dev musl-dev


```
Pipenv installed with `RUN pip install pipenv`

same here
```
[5/6] RUN pip install pipenv && pipenv install --system:    
#9 2.219 Collecting pipenv                              
#9 2.286   Downloading pipenv-2023.7.1-py3-none-any.whl (2.8 MB)                                                
#9 2.564      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.8/2.8 MB 10.2 MB/s eta 0:00:00
...
#9 10.03   File "/usr/local/lib/python3.7/site-packages/pipenv/project.py", line 1163, in python
#9 10.03     return project_python(self)
#9 10.03   File "/usr/local/lib/python3.7/site-packages/pipenv/utils/shell.py", line 404, in project_python
#9 10.03     python = project._which("python")
#9 10.03   File "/usr/local/lib/python3.7/site-packages/pipenv/project.py", line 1172, in _which
#9 10.03     raise RuntimeError("location not created nor specified")
#9 10.03 RuntimeError: location not created nor specified
```

Resolving patch:
diff --git a/pipenv/project.py b/pipenv/project.py
--- a/pipenv/project.py
+++ b/pipenv/project.py
@@ -1155,12 +1155,11 @@ def which(self, search, as_path=True):
                 result = str(result.path)
         return result
 
-    @property
-    def python(self) -> str:
+    def python(self, system=False) -> str:
         """Path to the project python"""
         from pipenv.utils.shell import project_python
 
-        return project_python(self)
+        return project_python(self, system=system)
 
     def _which(self, command, location=None, allow_global=False):
         if not allow_global and location is None:
diff --git a/pipenv/utils/project.py b/pipenv/utils/project.py
--- a/pipenv/utils/project.py
+++ b/pipenv/utils/project.py
@@ -79,4 +79,4 @@ def ensure_project(
         skip_requirements=skip_requirements,
         system=system,
     )
-    os.environ["PIP_PYTHON_PATH"] = project.python
+    os.environ["PIP_PYTHON_PATH"] = project.python(system=system)
diff --git a/pipenv/utils/resolver.py b/pipenv/utils/resolver.py
--- a/pipenv/utils/resolver.py
+++ b/pipenv/utils/resolver.py
@@ -1166,7 +1166,7 @@ def resolve_deps(
     req_dir = req_dir if req_dir else os.environ.get("req_dir", None)
     if not req_dir:
         req_dir = create_tracked_tempdir(prefix="pipenv-", suffix="-requirements")
-    with HackedPythonVersion(python_path=project.python):
+    with HackedPythonVersion(python_path=project.python(system=allow_global)):
         try:
             results, hashes, markers_lookup, resolver, skipped = actually_resolve_deps(
                 deps,
@@ -1185,7 +1185,7 @@ def resolve_deps(
     # Second (last-resort) attempt:
     if results is None:
         with HackedPythonVersion(
-            python_path=project.python,
+            python_path=project.python(system=allow_global),
         ):
             try:
                 # Attempt to resolve again, with different Python version information,


Test patch: