We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Error about `--user` and `--target` flag when installing xbuildenv
I sometimes get following error while installing xbuild environment:

```bash
$ pyodide build .
Downloading xbuild environment
Installing xbuild environment
  stderr:
    ERROR: Can not combine '--user' and '--target'

    [notice] A new release of pip available: 22.3.1 -> 23.0
    [notice] To update, run: /home/gitpod/.pyenv/versions/3.10.2/bin/python -m pip install --upgrade pip
```

It happens here, which installs host site packages:

https://github.com/pyodide/pyodide/blob/7cc1058358242a5a9012edbb8163d86a860a1a28/pyodide-build/pyodide_build/install_xbuildenv.py#L50-L57

I think we need to add `--no-user` flag explicitly to prevent this error.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pyodide-build/pyodide_build/install_xbuildenv.py`
Content:
```
1 import argparse
2 import json
3 import shutil
4 import subprocess
5 from pathlib import Path
6 from urllib.request import urlopen, urlretrieve
7 
8 from .common import exit_with_stdio, get_make_flag, get_pyodide_root
9 from .create_pypa_index import create_pypa_index
10 from .logger import logger
11 
12 
13 def make_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
14     parser.description = (
15         "Install xbuild env.\n\n"
16         "The installed environment is the same as the one that would result from\n"
17         "`PYODIDE_PACKAGES='scipy' make` except that it is much faster.\n"
18         "The goal is to enable out-of-tree builds for binary packages that depend\n"
19         "on numpy or scipy.\n"
20         "Note: this is a private endpoint that should not be used outside of the Pyodide Makefile."
21     )
22     parser.add_argument("--download", action="store_true", help="Download xbuild env")
23     parser.add_argument("xbuildenv", type=str, nargs=1)
24     return parser
25 
26 
27 def download_xbuildenv(version: str, xbuildenv_path: Path) -> None:
28     from shutil import rmtree, unpack_archive
29     from tempfile import NamedTemporaryFile
30 
31     logger.info("Downloading xbuild environment")
32     rmtree(xbuildenv_path, ignore_errors=True)
33     with NamedTemporaryFile(suffix=".tar") as f:
34         urlretrieve(
35             f"https://github.com/pyodide/pyodide/releases/download/{version}/xbuildenv-{version}.tar.bz2",
36             f.name,
37         )
38         unpack_archive(f.name, xbuildenv_path)
39 
40 
41 def install_xbuildenv(version: str, xbuildenv_path: Path) -> None:
42     logger.info("Installing xbuild environment")
43     xbuildenv_path = xbuildenv_path / "xbuildenv"
44     pyodide_root = get_pyodide_root()
45     xbuildenv_root = xbuildenv_path / "pyodide-root"
46     host_site_packages = xbuildenv_root / Path(
47         get_make_flag("HOSTSITEPACKAGES")
48     ).relative_to(pyodide_root)
49     host_site_packages.mkdir(exist_ok=True, parents=True)
50     result = subprocess.run(
51         [
52             "pip",
53             "install",
54             "-t",
55             host_site_packages,
56             "-r",
57             xbuildenv_path / "requirements.txt",
58         ],
59         capture_output=True,
60         encoding="utf8",
61     )
62     if result.returncode != 0:
63         exit_with_stdio(result)
64     # Copy the site-packages-extras (coming from the cross-build-files meta.yaml
65     # key) over the site-packages directory with the newly installed packages.
66     shutil.copytree(
67         xbuildenv_path / "site-packages-extras", host_site_packages, dirs_exist_ok=True
68     )
69     cdn_base = f"https://cdn.jsdelivr.net/pyodide/v{version}/full/"
70     if (xbuildenv_root / "repodata.json").exists():
71         repodata_bytes = (xbuildenv_root / "repodata.json").read_bytes()
72     else:
73         repodata_url = cdn_base + "repodata.json"
74         with urlopen(repodata_url) as response:
75             repodata_bytes = response.read()
76     repodata = json.loads(repodata_bytes)
77     version = repodata["info"]["version"]
78     create_pypa_index(repodata["packages"], xbuildenv_root, cdn_base)
79 
80 
81 def main(args: argparse.Namespace) -> None:
82     from . import __version__
83 
84     xbuildenv_path = Path(args.xbuildenv[0])
85     version = __version__
86     if args.download:
87         download_xbuildenv(version, xbuildenv_path)
88     install_xbuildenv(version, xbuildenv_path)
89
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pyodide-build/pyodide_build/install_xbuildenv.py b/pyodide-build/pyodide_build/install_xbuildenv.py
--- a/pyodide-build/pyodide_build/install_xbuildenv.py
+++ b/pyodide-build/pyodide_build/install_xbuildenv.py
@@ -51,6 +51,7 @@
         [
             "pip",
             "install",
+            "--no-user",
             "-t",
             host_site_packages,
             "-r",

{"golden_diff": "diff --git a/pyodide-build/pyodide_build/install_xbuildenv.py b/pyodide-build/pyodide_build/install_xbuildenv.py\n--- a/pyodide-build/pyodide_build/install_xbuildenv.py\n+++ b/pyodide-build/pyodide_build/install_xbuildenv.py\n@@ -51,6 +51,7 @@\n         [\n             \"pip\",\n             \"install\",\n+            \"--no-user\",\n             \"-t\",\n             host_site_packages,\n             \"-r\",\n", "issue": "Error about `--user` and `--target` flag when installing xbuildenv\nI sometimes get following error while installing xbuild environment:\r\n\r\n```bash\r\n$ pyodide build .\r\nDownloading xbuild environment\r\nInstalling xbuild environment\r\n  stderr:\r\n    ERROR: Can not combine '--user' and '--target'\r\n\r\n    [notice] A new release of pip available: 22.3.1 -> 23.0\r\n    [notice] To update, run: /home/gitpod/.pyenv/versions/3.10.2/bin/python -m pip install --upgrade pip\r\n```\r\n\r\nIt happens here, which installs host site packages:\r\n\r\nhttps://github.com/pyodide/pyodide/blob/7cc1058358242a5a9012edbb8163d86a860a1a28/pyodide-build/pyodide_build/install_xbuildenv.py#L50-L57\r\n\r\nI think we need to add `--no-user` flag explicitly to prevent this error.\n", "before_files": [{"content": "import argparse\nimport json\nimport shutil\nimport subprocess\nfrom pathlib import Path\nfrom urllib.request import urlopen, urlretrieve\n\nfrom .common import exit_with_stdio, get_make_flag, get_pyodide_root\nfrom .create_pypa_index import create_pypa_index\nfrom .logger import logger\n\n\ndef make_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:\n    parser.description = (\n        \"Install xbuild env.\\n\\n\"\n        \"The installed environment is the same as the one that would result from\\n\"\n        \"`PYODIDE_PACKAGES='scipy' make` except that it is much faster.\\n\"\n        \"The goal is to enable out-of-tree builds for binary packages that depend\\n\"\n        \"on numpy or scipy.\\n\"\n        \"Note: this is a private endpoint that should not be used outside of the Pyodide Makefile.\"\n    )\n    parser.add_argument(\"--download\", action=\"store_true\", help=\"Download xbuild env\")\n    parser.add_argument(\"xbuildenv\", type=str, nargs=1)\n    return parser\n\n\ndef download_xbuildenv(version: str, xbuildenv_path: Path) -> None:\n    from shutil import rmtree, unpack_archive\n    from tempfile import NamedTemporaryFile\n\n    logger.info(\"Downloading xbuild environment\")\n    rmtree(xbuildenv_path, ignore_errors=True)\n    with NamedTemporaryFile(suffix=\".tar\") as f:\n        urlretrieve(\n            f\"https://github.com/pyodide/pyodide/releases/download/{version}/xbuildenv-{version}.tar.bz2\",\n            f.name,\n        )\n        unpack_archive(f.name, xbuildenv_path)\n\n\ndef install_xbuildenv(version: str, xbuildenv_path: Path) -> None:\n    logger.info(\"Installing xbuild environment\")\n    xbuildenv_path = xbuildenv_path / \"xbuildenv\"\n    pyodide_root = get_pyodide_root()\n    xbuildenv_root = xbuildenv_path / \"pyodide-root\"\n    host_site_packages = xbuildenv_root / Path(\n        get_make_flag(\"HOSTSITEPACKAGES\")\n    ).relative_to(pyodide_root)\n    host_site_packages.mkdir(exist_ok=True, parents=True)\n    result = subprocess.run(\n        [\n            \"pip\",\n            \"install\",\n            \"-t\",\n            host_site_packages,\n            \"-r\",\n            xbuildenv_path / \"requirements.txt\",\n        ],\n        capture_output=True,\n        encoding=\"utf8\",\n    )\n    if result.returncode != 0:\n        exit_with_stdio(result)\n    # Copy the site-packages-extras (coming from the cross-build-files meta.yaml\n    # key) over the site-packages directory with the newly installed packages.\n    shutil.copytree(\n        xbuildenv_path / \"site-packages-extras\", host_site_packages, dirs_exist_ok=True\n    )\n    cdn_base = f\"https://cdn.jsdelivr.net/pyodide/v{version}/full/\"\n    if (xbuildenv_root / \"repodata.json\").exists():\n        repodata_bytes = (xbuildenv_root / \"repodata.json\").read_bytes()\n    else:\n        repodata_url = cdn_base + \"repodata.json\"\n        with urlopen(repodata_url) as response:\n            repodata_bytes = response.read()\n    repodata = json.loads(repodata_bytes)\n    version = repodata[\"info\"][\"version\"]\n    create_pypa_index(repodata[\"packages\"], xbuildenv_root, cdn_base)\n\n\ndef main(args: argparse.Namespace) -> None:\n    from . import __version__\n\n    xbuildenv_path = Path(args.xbuildenv[0])\n    version = __version__\n    if args.download:\n        download_xbuildenv(version, xbuildenv_path)\n    install_xbuildenv(version, xbuildenv_path)\n", "path": "pyodide-build/pyodide_build/install_xbuildenv.py"}], "after_files": [{"content": "import argparse\nimport json\nimport shutil\nimport subprocess\nfrom pathlib import Path\nfrom urllib.request import urlopen, urlretrieve\n\nfrom .common import exit_with_stdio, get_make_flag, get_pyodide_root\nfrom .create_pypa_index import create_pypa_index\nfrom .logger import logger\n\n\ndef make_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:\n    parser.description = (\n        \"Install xbuild env.\\n\\n\"\n        \"The installed environment is the same as the one that would result from\\n\"\n        \"`PYODIDE_PACKAGES='scipy' make` except that it is much faster.\\n\"\n        \"The goal is to enable out-of-tree builds for binary packages that depend\\n\"\n        \"on numpy or scipy.\\n\"\n        \"Note: this is a private endpoint that should not be used outside of the Pyodide Makefile.\"\n    )\n    parser.add_argument(\"--download\", action=\"store_true\", help=\"Download xbuild env\")\n    parser.add_argument(\"xbuildenv\", type=str, nargs=1)\n    return parser\n\n\ndef download_xbuildenv(version: str, xbuildenv_path: Path) -> None:\n    from shutil import rmtree, unpack_archive\n    from tempfile import NamedTemporaryFile\n\n    logger.info(\"Downloading xbuild environment\")\n    rmtree(xbuildenv_path, ignore_errors=True)\n    with NamedTemporaryFile(suffix=\".tar\") as f:\n        urlretrieve(\n            f\"https://github.com/pyodide/pyodide/releases/download/{version}/xbuildenv-{version}.tar.bz2\",\n            f.name,\n        )\n        unpack_archive(f.name, xbuildenv_path)\n\n\ndef install_xbuildenv(version: str, xbuildenv_path: Path) -> None:\n    logger.info(\"Installing xbuild environment\")\n    xbuildenv_path = xbuildenv_path / \"xbuildenv\"\n    pyodide_root = get_pyodide_root()\n    xbuildenv_root = xbuildenv_path / \"pyodide-root\"\n    host_site_packages = xbuildenv_root / Path(\n        get_make_flag(\"HOSTSITEPACKAGES\")\n    ).relative_to(pyodide_root)\n    host_site_packages.mkdir(exist_ok=True, parents=True)\n    result = subprocess.run(\n        [\n            \"pip\",\n            \"install\",\n            \"--no-user\",\n            \"-t\",\n            host_site_packages,\n            \"-r\",\n            xbuildenv_path / \"requirements.txt\",\n        ],\n        capture_output=True,\n        encoding=\"utf8\",\n    )\n    if result.returncode != 0:\n        exit_with_stdio(result)\n    # Copy the site-packages-extras (coming from the cross-build-files meta.yaml\n    # key) over the site-packages directory with the newly installed packages.\n    shutil.copytree(\n        xbuildenv_path / \"site-packages-extras\", host_site_packages, dirs_exist_ok=True\n    )\n    cdn_base = f\"https://cdn.jsdelivr.net/pyodide/v{version}/full/\"\n    if (xbuildenv_root / \"repodata.json\").exists():\n        repodata_bytes = (xbuildenv_root / \"repodata.json\").read_bytes()\n    else:\n        repodata_url = cdn_base + \"repodata.json\"\n        with urlopen(repodata_url) as response:\n            repodata_bytes = response.read()\n    repodata = json.loads(repodata_bytes)\n    version = repodata[\"info\"][\"version\"]\n    create_pypa_index(repodata[\"packages\"], xbuildenv_root, cdn_base)\n\n\ndef main(args: argparse.Namespace) -> None:\n    from . import __version__\n\n    xbuildenv_path = Path(args.xbuildenv[0])\n    version = __version__\n    if args.download:\n        download_xbuildenv(version, xbuildenv_path)\n    install_xbuildenv(version, xbuildenv_path)\n", "path": "pyodide-build/pyodide_build/install_xbuildenv.py"}]}