Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion install-poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,16 @@ def make(cls, target: Path) -> "VirtualEnvironment":
import ensurepip # noqa: F401
import venv

if sys.platform == "darwin" and "/Library/Developer/CommandLineTools" in (
sys.executable or ""
):
# The macOS Xcode Command Line Tools Python is a stub (e.g. /usr/bin/python3 ->
# /Library/Developer/CommandLineTools/usr/bin/python3) whose venv bin/python
# carries an unresolvable `@executable_path/../Python3` loader reference, so
# pip (and therefore the poetry install) fails with a dyld error. Use the
# robust virtualenv bootstrap (--always-copy) below to create a self-contained venv.
raise ImportError

builder = venv.EnvBuilder(clear=True, with_pip=True, symlinks=False)
context = builder.ensure_directories(target)

Expand All @@ -339,7 +349,9 @@ def make(cls, target: Path) -> "VirtualEnvironment":

builder.create(target)
except ImportError:
# fallback to using virtualenv package if venv is not available, eg: ubuntu
# fallback to using virtualenv package if venv is not available (eg: ubuntu)
# or if the base interpreter is the macOS Command Line Tools stub which
# produces a broken venv
python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
virtualenv_bootstrap_url = (
f"https://bootstrap.pypa.io/virtualenv/{python_version}/virtualenv.pyz"
Expand Down