uv: In-tree build `uv pip install .` will create PEP-517 venv twice which breaks build-requires (e.g., `cmake` / `ninja` with absolute path in first venv)
Summary
As per the issue title, uv pip install [-e ]. will create two venv. For PyTorch, the setup.py will run CMake commands, which generate Ninja build commands. As the following trimmed log reports, the ninja command does not exist. The absolute path of the ninja command is in the first venv, which is removed after build. The ninja command is installed in the second venv but not invoked because the ninja command is invoked by absolute path.
`uv pip install -v -e .` log
$ uv pip install -v -e .
DEBUG uv 0.7.15
DEBUG Marking explicit source tree for reinstall: `/home/panxuehai/Projects/pytorch`
DEBUG Searching for default Python interpreter in virtual environments
DEBUG Found `cpython-3.13.3-linux-x86_64-gnu` at `/home/panxuehai/Projects/pytorch/venv/bin/python3` (active virtual environment)
Using Python 3.13.3 environment at: venv
DEBUG Acquired lock for `venv`
DEBUG Using request timeout of 30s
DEBUG Found PEP 621 metadata for /home/panxuehai/Projects/pytorch in `pyproject.toml` (torch)
DEBUG No static `pyproject.toml` available for: torch @ file:///home/panxuehai/Projects/pytorch (DynamicField("dependencies"))
DEBUG Acquired lock for `/home/panxuehai/.cache/uv/sdists-v9/editable/17f48f3bb31b12e6`
DEBUG Computed cache info: Some(Timestamp(SystemTime { tv_sec: 1750927304, tv_nsec: 527953603 })), None, None, {}, {"src": None}
DEBUG Preparing metadata for: torch @ file:///home/panxuehai/Projects/pytorch
DEBUG No workspace root found, using project root
DEBUG Assessing Python executable as base candidate: /home/panxuehai/.local/share/uv/python/cpython-3.13.3-linux-x86_64-gnu/bin/python3.13
DEBUG Using base executable for virtual environment: /home/panxuehai/.local/share/uv/python/cpython-3.13.3-linux-x86_64-gnu/bin/python3.13
DEBUG Ignoring empty directory
DEBUG Resolving build requirements
DEBUG Solving with installed Python version: 3.13.3
DEBUG Solving with target Python version: >=3.13.3
DEBUG Adding direct dependency: setuptools>=62.3.0
DEBUG Adding direct dependency: wheel*
DEBUG Adding direct dependency: astunparse*
DEBUG Adding direct dependency: cmake>=3.27
DEBUG Adding direct dependency: ninja*
DEBUG Adding direct dependency: numpy*
DEBUG Adding direct dependency: pyyaml*
DEBUG Adding direct dependency: requests*
DEBUG Adding direct dependency: typing-extensions>=4.10.0
DEBUG
DEBUG > ...
DEBUG > Resolving venv
DEBUG > ...
DEBUG
DEBUG Installing in idna==3.10, charset-normalizer==3.4.2, pyyaml==6.0.2, astunparse==1.6.3, cmake==4.0.3, urllib3==2.5.0, ninja==1.11.1.4, typing-extensions==4.14.0, six==1.17.0, requests==2.32.4, numpy==2.3.1, certifi==2025.6.15, wheel==0.45.1, setuptools==80.9.0 in /home/panxuehai/.cache/uv/builds-v0/.tmp8yZxY0
DEBUG Registry requirement already cached: idna==3.10
DEBUG Registry requirement already cached: charset-normalizer==3.4.2
DEBUG Registry requirement already cached: pyyaml==6.0.2
DEBUG Registry requirement already cached: astunparse==1.6.3
DEBUG Registry requirement already cached: cmake==4.0.3
DEBUG Registry requirement already cached: urllib3==2.5.0
DEBUG Registry requirement already cached: ninja==1.11.1.4
DEBUG Registry requirement already cached: typing-extensions==4.14.0
DEBUG Registry requirement already cached: six==1.17.0
DEBUG Registry requirement already cached: requests==2.32.4
DEBUG Registry requirement already cached: numpy==2.3.1
DEBUG Registry requirement already cached: certifi==2025.6.15
DEBUG Registry requirement already cached: wheel==0.45.1
DEBUG Registry requirement already cached: setuptools==80.9.0
DEBUG Installing build requirements: idna==3.10, charset-normalizer==3.4.2, pyyaml==6.0.2, astunparse==1.6.3, cmake==4.0.3, urllib3==2.5.0, ninja==1.11.1.4, typing-extensions==4.14.0, six==1.17.0, requests==2.32.4, numpy==2.3.1, certifi==2025.6.15, wheel==0.45.1, setuptools==80.9.0
# DEBUG Creating PEP 517 build environment
DEBUG Calling `setuptools.build_meta.get_requires_for_build_editable()`
DEBUG Building wheel torch-2.8.0a0+git1c5da4f
# DEBUG running egg_info
DEBUG writing torch.egg-info/PKG-INFO
DEBUG writing dependency_links to torch.egg-info/dependency_links.txt
DEBUG writing entry points to torch.egg-info/entry_points.txt
DEBUG writing requirements to torch.egg-info/requires.txt
DEBUG writing top-level names to torch.egg-info/top_level.txt
DEBUG reading manifest file 'torch.egg-info/SOURCES.txt'
DEBUG reading manifest template 'MANIFEST.in'
DEBUG warning: no previously-included files matching '*.o' found anywhere in distribution
DEBUG warning: no previously-included files matching '*.obj' found anywhere in distribution
DEBUG warning: no previously-included files matching '*.dylib' found anywhere in distribution
DEBUG no previously-included directories found matching '*/.git'
DEBUG warning: no previously-included files matching '*~' found anywhere in distribution
DEBUG warning: no previously-included files matching '*.swp' found anywhere in distribution
DEBUG adding license file 'LICENSE'
DEBUG adding license file 'NOTICE'
DEBUG writing manifest file 'torch.egg-info/SOURCES.txt'
DEBUG No workspace root found, using project root
DEBUG Calling `setuptools.build_meta.prepare_metadata_for_build_editable()`
DEBUG Building wheel torch-2.8.0a0+git1c5da4f
DEBUG -- Building version 2.8.0a0+git1c5da4f
DEBUG
DEBUG > ...
DEBUG > CMake Configure Log ...
DEBUG > ...
DEBUG
DEBUG -- Configuring done (44.7s)
DEBUG -- Generating done (3.2s)
DEBUG -- Build files have been written to: /home/panxuehai/Projects/pytorch/build
DEBUG [1/4] Generating ATen declarations_yaml
DEBUG [2/4] Generating ATen headers
DEBUG [3/4] Generating ATen sources
DEBUG [1/811] Creating directories for 'nccl_external'
DEBUG
DEBUG > ...
DEBUG > CMake Build Log ...
DEBUG > ...
DEBUG
DEBUG cmake -GNinja -DBUILD_PYTHON=True -DBUILD_TEST=True -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/panxuehai/Projects/pytorch/torch -DCMAKE_PREFIX_PATH=/home/panxuehai/.cache/uv/builds-v0/.tmp8yZxY0/lib/python3.13/site-packages -DPython_EXECUTABLE=/home/panxuehai/.cache/uv/builds-v0/.tmp8yZxY0/bin/python -DTORCH_BUILD_VERSION=2.8.0a0+git1c5da4f -DUSE_NUMPY=True /home/panxuehai/Projects/pytorch
DEBUG cmake --build . --target install --config Release
# DEBUG running dist_info
DEBUG creating /home/panxuehai/.cache/uv/builds-v0/.tmp8yZxY0/metadata_directory/torch.egg-info
DEBUG writing /home/panxuehai/.cache/uv/builds-v0/.tmp8yZxY0/metadata_directory/torch.egg-info/PKG-INFO
DEBUG writing dependency_links to /home/panxuehai/.cache/uv/builds-v0/.tmp8yZxY0/metadata_directory/torch.egg-info/dependency_links.txt
DEBUG writing entry points to /home/panxuehai/.cache/uv/builds-v0/.tmp8yZxY0/metadata_directory/torch.egg-info/entry_points.txt
DEBUG writing requirements to /home/panxuehai/.cache/uv/builds-v0/.tmp8yZxY0/metadata_directory/torch.egg-info/requires.txt
DEBUG writing top-level names to /home/panxuehai/.cache/uv/builds-v0/.tmp8yZxY0/metadata_directory/torch.egg-info/top_level.txt
DEBUG writing manifest file '/home/panxuehai/.cache/uv/builds-v0/.tmp8yZxY0/metadata_directory/torch.egg-info/SOURCES.txt'
DEBUG reading manifest file '/home/panxuehai/.cache/uv/builds-v0/.tmp8yZxY0/metadata_directory/torch.egg-info/SOURCES.txt'
DEBUG reading manifest template 'MANIFEST.in'
DEBUG warning: no previously-included files matching '*.o' found anywhere in distribution
DEBUG warning: no previously-included files matching '*.obj' found anywhere in distribution
DEBUG warning: no previously-included files matching '*.dylib' found anywhere in distribution
DEBUG no previously-included directories found matching '*/.git'
DEBUG warning: no previously-included files matching '*~' found anywhere in distribution
DEBUG warning: no previously-included files matching '*.swp' found anywhere in distribution
DEBUG adding license file 'LICENSE'
DEBUG adding license file 'NOTICE'
DEBUG writing manifest file '/home/panxuehai/.cache/uv/builds-v0/.tmp8yZxY0/metadata_directory/torch.egg-info/SOURCES.txt'
DEBUG creating '/home/panxuehai/.cache/uv/builds-v0/.tmp8yZxY0/metadata_directory/torch-2.8.0a0+git1c5da4f.dist-info'
DEBUG Prepared metadata for: torch @ file:///home/panxuehai/Projects/pytorch
DEBUG No workspace root found, using project root
DEBUG Released lock at `/home/panxuehai/.cache/uv/sdists-v9/editable/17f48f3bb31b12e6/.lock`
DEBUG Solving with installed Python version: 3.13.3
DEBUG Solving with target Python version: >=3.13.3
DEBUG Adding direct dependency: torch*
DEBUG Searching for a compatible version of torch @ file:///home/panxuehai/Projects/pytorch (*)
DEBUG Adding transitive dependency for torch==2.8.0a0+git1c5da4f: filelock*
DEBUG Adding transitive dependency for torch==2.8.0a0+git1c5da4f: typing-extensions>=4.10.0
DEBUG Adding transitive dependency for torch==2.8.0a0+git1c5da4f: setuptools{python_full_version >= '3.12'}*
DEBUG Adding transitive dependency for torch==2.8.0a0+git1c5da4f: sympy>=1.13.3
DEBUG Adding transitive dependency for torch==2.8.0a0+git1c5da4f: networkx*
DEBUG Adding transitive dependency for torch==2.8.0a0+git1c5da4f: jinja2*
DEBUG Adding transitive dependency for torch==2.8.0a0+git1c5da4f: fsspec*
DEBUG ...
DEBUG Resolving venv
DEBUG ...
DEBUG Requirement already installed: sympy==1.14.0
DEBUG Requirement already installed: markupsafe==3.0.2
DEBUG Requirement already installed: filelock==3.18.0
DEBUG Must revalidate requirement: torch
DEBUG Requirement already installed: networkx==3.5
DEBUG Requirement already installed: typing-extensions==4.14.0
DEBUG Requirement already installed: jinja2==3.1.6
DEBUG Requirement already installed: fsspec==2025.5.1
DEBUG Requirement already installed: mpmath==1.3.0
DEBUG Requirement already installed: setuptools==80.9.0
DEBUG Unnecessary package: pyyaml==6.0.2
DEBUG Unnecessary package: aiohappyeyeballs==2.6.1
DEBUG Unnecessary package: aiohttp==3.12.13
DEBUG Unnecessary package: aiosignal==1.3.2
DEBUG Unnecessary package: astroid==3.3.10
DEBUG Unnecessary package: asttokens==3.0.0
DEBUG Unnecessary package: astunparse==1.6.3
DEBUG Unnecessary package: attrs==25.3.0
DEBUG Unnecessary package: build==1.2.2.post1
DEBUG Unnecessary package: certifi==2025.6.15
DEBUG Unnecessary package: charset-normalizer==3.4.2
DEBUG Unnecessary package: click==8.2.1
DEBUG Unnecessary package: cmake==4.0.3
DEBUG Unnecessary package: decorator==5.2.1
DEBUG Unnecessary package: dill==0.4.0
DEBUG Unnecessary package: executing==2.2.0
DEBUG Unnecessary package: expecttest==0.3.0
DEBUG Unnecessary package: flake8==7.3.0
DEBUG Unnecessary package: frozenlist==1.7.0
DEBUG Unnecessary package: ghstack==0.11.0
DEBUG Unnecessary package: hypothesis==6.135.15
DEBUG Unnecessary package: idna==3.10
DEBUG Unnecessary package: ipython==9.3.0
DEBUG Unnecessary package: ipython-pygments-lexers==1.1.1
DEBUG Unnecessary package: isort==6.0.1
DEBUG Unnecessary package: jedi==0.19.2
DEBUG Unnecessary package: lintrunner==0.12.7
DEBUG Unnecessary package: markdown-it-py==3.0.0
DEBUG Unnecessary package: matplotlib-inline==0.1.7
DEBUG Unnecessary package: mccabe==0.7.0
DEBUG Unnecessary package: mdurl==0.1.2
DEBUG Unnecessary package: multidict==6.5.1
DEBUG Unnecessary package: mypy==1.16.1
DEBUG Unnecessary package: mypy-extensions==1.1.0
DEBUG Unnecessary package: ninja==1.11.1.4
DEBUG Unnecessary package: numpy==2.3.1
DEBUG Unnecessary package: optree==0.16.0
DEBUG Unnecessary package: packaging==25.0
DEBUG Unnecessary package: parso==0.8.4
DEBUG Unnecessary package: pathspec==0.12.1
DEBUG Unnecessary package: pexpect==4.9.0
DEBUG Preserving seed package: pip==25.1.1
DEBUG Unnecessary package: platformdirs==4.3.8
DEBUG Unnecessary package: prompt-toolkit==3.0.51
DEBUG Unnecessary package: propcache==0.3.2
DEBUG Unnecessary package: psutil==7.0.0
DEBUG Unnecessary package: ptyprocess==0.7.0
DEBUG Unnecessary package: pure-eval==0.2.3
DEBUG Unnecessary package: pycodestyle==2.14.0
DEBUG Unnecessary package: pyenchant==3.2.2
DEBUG Unnecessary package: pyflakes==3.4.0
DEBUG Unnecessary package: pygments==2.19.2
DEBUG Unnecessary package: pylint==3.3.7
DEBUG Unnecessary package: pyproject-hooks==1.2.0
DEBUG Unnecessary package: requests==2.32.4
DEBUG Unnecessary package: rich==14.0.0
DEBUG Unnecessary package: ruff==0.12.0
DEBUG Unnecessary package: six==1.17.0
DEBUG Unnecessary package: sortedcontainers==2.4.0
DEBUG Unnecessary package: stack-data==0.6.3
DEBUG Unnecessary package: tomlkit==0.13.3
DEBUG Unnecessary package: traitlets==5.14.3
DEBUG Unnecessary package: types-dataclasses==0.6.6
DEBUG Unnecessary package: urllib3==2.5.0
DEBUG Preserving seed package: uv==0.7.15
DEBUG Unnecessary package: wcwidth==0.2.13
DEBUG Unnecessary package: wheel==0.45.1
DEBUG Unnecessary package: yarl==1.20.1
DEBUG Acquired lock for `/home/panxuehai/.cache/uv/sdists-v9/editable/17f48f3bb31b12e6`
DEBUG Computed cache info: Some(Timestamp(SystemTime { tv_sec: 1750927304, tv_nsec: 527953603 })), None, None, {}, {"src": None}
Building torch @ file:///home/panxuehai/Projects/pytorch
DEBUG Building: torch @ file:///home/panxuehai/Projects/pytorch
DEBUG No workspace root found, using project root
DEBUG Assessing Python executable as base candidate: /home/panxuehai/.local/share/uv/python/cpython-3.13.3-linux-x86_64-gnu/bin/python3.13
DEBUG Using base executable for virtual environment: /home/panxuehai/.local/share/uv/python/cpython-3.13.3-linux-x86_64-gnu/bin/python3.13
DEBUG Ignoring empty directory
DEBUG Resolving build requirements
DEBUG Solving with installed Python version: 3.13.3
DEBUG Solving with target Python version: >=3.13.3
DEBUG Adding direct dependency: setuptools>=62.3.0
DEBUG Adding direct dependency: wheel*
DEBUG Adding direct dependency: astunparse*
DEBUG Adding direct dependency: cmake>=3.27
DEBUG Adding direct dependency: ninja*
DEBUG Adding direct dependency: numpy*
DEBUG Adding direct dependency: pyyaml*
DEBUG Adding direct dependency: requests*
DEBUG Adding direct dependency: typing-extensions>=4.10.0
DEBUG
DEBUG > ...
DEBUG > Resolving venv
DEBUG > ...
DEBUG
DEBUG Installing in idna==3.10, charset-normalizer==3.4.2, pyyaml==6.0.2, astunparse==1.6.3, cmake==4.0.3, urllib3==2.5.0, ninja==1.11.1.4, typing-extensions==4.14.0, six==1.17.0, requests==2.32.4, numpy==2.3.1, certifi==2025.6.15, wheel==0.45.1, setuptools==80.9.0 in /home/panxuehai/.cache/uv/builds-v0/.tmpBE9W53
DEBUG Registry requirement already cached: idna==3.10
DEBUG Registry requirement already cached: charset-normalizer==3.4.2
DEBUG Registry requirement already cached: pyyaml==6.0.2
DEBUG Registry requirement already cached: astunparse==1.6.3
DEBUG Registry requirement already cached: cmake==4.0.3
DEBUG Registry requirement already cached: urllib3==2.5.0
DEBUG Registry requirement already cached: ninja==1.11.1.4
DEBUG Registry requirement already cached: typing-extensions==4.14.0
DEBUG Registry requirement already cached: six==1.17.0
DEBUG Registry requirement already cached: requests==2.32.4
DEBUG Registry requirement already cached: numpy==2.3.1
DEBUG Registry requirement already cached: certifi==2025.6.15
DEBUG Registry requirement already cached: wheel==0.45.1
DEBUG Registry requirement already cached: setuptools==80.9.0
DEBUG Installing build requirements: idna==3.10, charset-normalizer==3.4.2, pyyaml==6.0.2, astunparse==1.6.3, cmake==4.0.3, urllib3==2.5.0, ninja==1.11.1.4, typing-extensions==4.14.0, six==1.17.0, requests==2.32.4, numpy==2.3.1, certifi==2025.6.15, wheel==0.45.1, setuptools==80.9.0
# DEBUG Creating PEP 517 build environment
DEBUG Calling `setuptools.build_meta.get_requires_for_build_editable()`
DEBUG Building wheel torch-2.8.0a0+git1c5da4f
# DEBUG running egg_info
DEBUG writing torch.egg-info/PKG-INFO
DEBUG writing dependency_links to torch.egg-info/dependency_links.txt
DEBUG writing entry points to torch.egg-info/entry_points.txt
DEBUG writing requirements to torch.egg-info/requires.txt
DEBUG writing top-level names to torch.egg-info/top_level.txt
DEBUG reading manifest file 'torch.egg-info/SOURCES.txt'
DEBUG reading manifest template 'MANIFEST.in'
DEBUG warning: no previously-included files matching '*.o' found anywhere in distribution
DEBUG warning: no previously-included files matching '*.obj' found anywhere in distribution
DEBUG warning: no previously-included files matching '*.dylib' found anywhere in distribution
DEBUG no previously-included directories found matching '*/.git'
DEBUG warning: no previously-included files matching '*~' found anywhere in distribution
DEBUG warning: no previously-included files matching '*.swp' found anywhere in distribution
DEBUG adding license file 'LICENSE'
DEBUG adding license file 'NOTICE'
DEBUG writing manifest file 'torch.egg-info/SOURCES.txt'
DEBUG No workspace root found, using project root
DEBUG Calling `setuptools.build_meta.build_editable("/home/panxuehai/.cache/uv/builds-v0/.tmpfM5YkL", {}, None)`
DEBUG Building wheel torch-2.8.0a0+git1c5da4f
DEBUG -- Building version 2.8.0a0+git1c5da4f
DEBUG no such file or directory
DEBUG CMake Error: Generator: build tool execution failed, command was: /home/panxuehai/.cache/uv/builds-v0/.tmp8yZxY0/bin/ninja install
DEBUG -- Checkout nccl release tag: v2.27.3-1
DEBUG cmake --build . --target install --config Release
DEBUG Released lock at `/home/panxuehai/.cache/uv/sdists-v9/editable/17f48f3bb31b12e6/.lock`
× Failed to build `torch @ file:///home/panxuehai/Projects/pytorch`
├─▶ The build backend returned an error
╰─▶ Call to `setuptools.build_meta.build_editable` failed (exit status: 1)
[stdout]
-- Checkout nccl release tag: v2.27.3-1
cmake --build . --target install --config Release
[stderr]
Building wheel torch-2.8.0a0+git1c5da4f
-- Building version 2.8.0a0+git1c5da4f
no such file or directory
CMake Error: Generator: build tool execution failed, command was: /home/panxuehai/.cache/uv/builds-v0/.tmp8yZxY0/bin/ninja install
hint: This usually indicates a problem with the package or the build environment.
DEBUG Released lock at `/home/panxuehai/Projects/pytorch/venv/.lock`
For detailed build log:
PR pytorch/pytorch#156709 fixes the PyTorch build failure caused by uv pip install creates two PEP-517 venv, that does not run CMake for python setup.py dist_info. But uv pip install still creates two PEP-517 venv. FYI, pip install works fine without that fix.
- pytorch/pytorch#156709
Build commands for PyTorch:
git clone --recurse-submodules --branch=pyproject https://github.com/XuehaiPan/pytorch.git && cd pytorch
uv venv venv
source venv/bin/activate
fd -HI 'CMakeCache\.txt|.*\.ninja.*' | xargs -I '{}' bash -c "echo '{}'; rm -rf '{}'"
uv pip install -v -e .
Platform
Ubuntu 20.04 amd64
Version
uv 0.7.15
Python version
Python 3.13.3
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 27 (16 by maintainers)
Commits related to this issue
- Reuse build (virtual) environments across resolution and installation (#14338) ## Summary The basic idea here is that we can (should) reuse a build environment across resolution (`prepare_metadata_f... — committed to astral-sh/uv by charliermarsh a year ago
- Only drop build directories on program exit (#14304) ## Summary This PR ensures that we avoid cleaning up build directories until the end of a resolve-and-install cycle. It's not bulletproof (since ... — committed to dpprdan/uv by charliermarsh a year ago
- [build] remove cmake cache and reconfigure again if it is invalid (#156958) See also: - astral-sh/uv#14269 Pull Request resolved: https://github.com/pytorch/pytorch/pull/156958 Approved by: https:/... — committed to pytorch/pytorch by XuehaiPan a year ago
We may be talking past each other here: uv totally keeps the source tree around and editable builds in that source tree. Only the build venv is ephemeral and may change places.
To make this more concrete for the torch case: The problem is that cmake has generated an absolute path for ninja, and stores it in
CMakeCache.txt. This means the build will fail when e.g. switching fromuv pip install -e .andpython -m build. I tried to hack it into the torch build system to replace those paths with the current one, but the absolute paths seems pervasive with no option to change to change or invalidate this in cmake without rebuilding torch.The
builddirectory. And it’s backend-specific, so passed on via config-settings. It’s-Cbuild-dir=<builddir>in bothmeson-pythonandscikit-build-core.Side note: this is an interesting puzzle, but I’m about to sign off for a week of holiday, so I will probably be slow in responding. Perhaps we should get together at some point and see if we can talk through this stuff - there’s a lot that could be better specified or improved.
100%, thank you for engaging here and helping me understand! (Also: hope you have a great holiday!)
Hmm… I’m not totally convinced that it’s acceptable for
build_wheelto fail becauseprepare_metadata_for_build_wheelwas called with a separate build environment (and we are preserving the files created outside the build directory; they’re just referencing files that are later removed), but I understand that the “two environment” approach here doesn’t really match the intent of the PEP. I might be wrong, though – I know you’ve thought about the frontend/backend relationship a lot. I think we should support this use-case either way.Honestly I think this isn’t a bug in uv – it’s likely a violation of the spec to be caching in this way. But we should probably still support it.