File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -327,6 +327,14 @@ def make(cls, target: Path) -> "VirtualEnvironment":
327327 import ensurepip # noqa: F401
328328 import venv
329329
330+ if sys .platform == "darwin" and "/Library/Developer/CommandLineTools" in (sys .executable or "" ):
331+ # The macOS Xcode Command Line Tools Python is a stub (e.g. /usr/bin/python3 ->
332+ # /Library/Developer/CommandLineTools/usr/bin/python3) whose venv bin/python
333+ # carries an unresolvable `@executable_path/../Python3` loader reference, so
334+ # pip (and therefore the poetry install) fails with a dyld error. Use the
335+ # robust virtualenv bootstrap (--always-copy) below to create a self-contained venv.
336+ raise ImportError
337+
330338 builder = venv .EnvBuilder (clear = True , with_pip = True , symlinks = False )
331339 context = builder .ensure_directories (target )
332340
@@ -339,7 +347,9 @@ def make(cls, target: Path) -> "VirtualEnvironment":
339347
340348 builder .create (target )
341349 except ImportError :
342- # fallback to using virtualenv package if venv is not available, eg: ubuntu
350+ # fallback to using virtualenv package if venv is not available (eg: ubuntu)
351+ # or if the base interpreter is the macOS Command Line Tools stub which
352+ # produces a broken venv
343353 python_version = f"{ sys .version_info .major } .{ sys .version_info .minor } "
344354 virtualenv_bootstrap_url = (
345355 f"https://bootstrap.pypa.io/virtualenv/{ python_version } /virtualenv.pyz"
You can’t perform that action at this time.
0 commit comments