如何用uv为基于setuptools的flash-attention项目构建Wheel包?
问题
我在Windows系统的uv环境中,通过克隆Git仓库并执行uv pip install . --no-build-isolation,成功从源码安装了基于setuptools的flash-attention项目。由于编译耗时长达2小时,我想构建它的Wheel包以避免重复编译,但执行uv run setup.py bdist_wheel时失败,报错显示找不到pip(推测是uv替换了自身版本的pip),具体错误如下:
torch.__version__ = 2.8.0+cu128 FOLDER\.venv\Lib\site-packages\setuptools\__init__.py:92: _DeprecatedInstaller: setuptools.installer and fetch_build_eggs are deprecated. !! ******************************************************************************** Requirements should be satisfied by a PEP 517 installer. If you are using pip, you can try `pip install --use-pep517`. By 2025-Oct-31, you need to update your project and remove deprecated calls or your builds will no longer be supported. ******************************************************************************** !! dist.fetch_build_eggs(dist.setup_requires) FOLDER\.venv\Scripts\python.exe: No module named pip Traceback (most recent call last): File "FOLDER\.venv\Lib\site-packages\setuptools\installer.py", line 121, in _fetch_build_egg_no_warn subprocess.check_call(cmd) ~~~~~~~~~~~~~~~~~~~~~^^^^^ File "FOLDER\uv\python\cpython-3.13.3-windows-x86_64-none\Lib\subprocess.py", line 419, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['FOLDER\\.venv\\Scripts\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\raffaele\\AppData\\Local\\Temp\\tmp4kqx99sl', '--quiet', 'ninja']' returned non-zero exit status 1. The above exception was the direct cause of the following exception: Traceback (most recent call last): File "FOLDER\flash-attention\setup.py", line 570, in <module> setup( ~~~~~^ name=PACKAGE_NAME, ^^^^^^^^^^^^^^^^^^ ...<39 lines>... ], ^^ ) ^ File "FOLDER\.venv\Lib\site-packages\setuptools\__init__.py", line 114, in setup _install_setup_requires(attrs) ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^ File "FOLDER\.venv\Lib\site-packages\setuptools\__init__.py", line 87, in _install_setup_requires _fetch_build_eggs(dist) ~~~~~~~~~~~~~~~~~^^^^^^ File "FOLDER\.venv\Lib\site-packages\setuptools\__init__.py", line 92, in _fetch_build_eggs dist.fetch_build_eggs(dist.setup_requires) ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^ File "FOLDER\.venv\Lib\site-packages\setuptools\dist.py", line 766, in fetch_build_eggs return _fetch_build_eggs(self, requires) File "FOLDER\.venv\Lib\site-packages\setuptools\installer.py", line 54, in _fetch_build_eggs resolved_dists = [_fetch_build_egg_no_warn(dist, req) for req in needed_reqs] ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^ File "FOLDER\.venv\Lib\site-packages\setuptools\installer.py", line 123, in _fetch_build_egg_no_warn raise DistutilsError(str(e)) from e distutils.errors.DistutilsError: Command '['FOLDER\\.venv\\Scripts\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'TEMP_FOLDER\\tmp4kqx99sl', '--quiet', 'ninja']' returned non-zero exit status 1.
请问如何使用uv为该基于setuptools的项目构建Wheel包?
解决方案
方法一:使用uv官方推荐的PEP 517构建命令(优先选择)
uv内置了符合PEP 517标准的构建工具,无需依赖虚拟环境中的pip,直接在项目根目录执行:
uv build
执行完成后,生成的Wheel包会存放在项目根目录的dist文件夹中。
方法二:补装pip后使用setup.py构建
如果坚持使用传统的setup.py方式,需要先在uv虚拟环境中安装pip,再执行构建命令:
- 安装pip到虚拟环境:
uv pip install pip
- 执行Wheel构建:
uv run setup.py bdist_wheel
报错原因说明
uv创建的虚拟环境默认不会安装pip,而flash-attention的setup.py使用了setuptools已废弃的fetch_build_eggs方法,该方法会调用pip来安装构建依赖(如ninja),因此出现找不到pip的错误。uv build采用PEP 517规范,无需依赖虚拟环境内的pip,更适配uv的生态。
内容的提问来源于stack exchange,提问作者robertspierre
相关产品推荐
相关产品推荐

