You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行pip install xformers遇编译错误,无法构建wheel包求助

问题:pip安装xformers时无法构建wheel包

执行pip install xformers时遇到错误:

Could not build wheels for xformers, which is required to install pyproject.toml-based projects

完整报错信息:

The above exception was the direct cause of the following exception:
      
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/v6/5nfg7gwj3pv9v3pggcqn693c0000gn/T/pip-install-1042wqay/xformers_5a89fc0ef70149b49276d6c7fc8f19bb/setup.py", line 419, in <module>
          setuptools.setup(
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/__init__.py", line 103, in setup
          return distutils.core.setup(**attrs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 185, in setup
          return run_commands(dist)
                 ^^^^^^^^^^^^^^^^^^
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
          dist.run_commands()
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/dist.py", line 963, in run_command
          super().run_command(command)
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/wheel/bdist_wheel.py", line 364, in run
          self.run_command("build")
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/dist.py", line 963, in run_command
          super().run_command(command)
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/_distutils/command/build.py", line 131, in run
          self.run_command(cmd_name)
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/dist.py", line 963, in run_command
          super().run_command(command)
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/command/build_ext.py", line 88, in run
          _build_ext.run(self)
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/_distutils/command/build_ext.py", line 345, in run
          self.build_extensions()
        File "/private/var/folders/v6/5nfg7gwj3pv9v3pggcqn693c0000gn/T/pip-install-1042wqay/xformers_5a89fc0ef70149b49276d6c7fc8f19bb/setup.py", line 364, in build_extensions
          super().build_extensions()
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/torch/utils/cpp_extension.py", line 843, in build_extensions
          build_ext.build_extensions(self)
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/_distutils/command/build_ext.py", line 467, in build_extensions
          self._build_extensions_serial()
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/_distutils/command/build_ext.py", line 493, in _build_extensions_serial
          self.build_extension(ext)
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/command/build_ext.py", line 249, in build_extension
          _build_ext.build_extension(self, ext)
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/setuptools/_distutils/command/build_ext.py", line 548, in build_extension
          objects = self.compiler.compile(
                    ^^^^^^^^^^^^^^^^^^^^^^
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/torch/utils/cpp_extension.py", line 658, in unix_wrap_ninja_compile
          _write_ninja_file_and_compile_objects(
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/torch/utils/cpp_extension.py", line 1574, in _write_ninja_file_and_compile_objects
          _run_ninja_build(
        File "/Users/fengyuanliu/anaconda3/envs/pytorch/lib/python3.11/site-packages/torch/utils/cpp_extension.py", line 1909, in _run_ninja_build
          raise RuntimeError(message) from e
      RuntimeError: Error compiling objects for extension
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for xformers
  Running setup.py clean for xformers
Failed to build xformers
ERROR: Could not build wheels for xformers, which is required to install pyproject.toml-based projects

已尝试的无效操作:

  • 升级pip
  • 误安装了xformer(已确认与xformers为不同包)

当前环境pip list:

accelerate                    0.26.1
altgraph                      0.17.4
appnope                       0.1.3
asttokens                     2.4.1
backcall                      0.2.0
backports.functools-lru-cache 1.6.5
Bottleneck                    1.3.5
Brotli                        1.0.9
certifi                       2023.7.22
cffi                          1.15.1
charset-normalizer            2.0.4
comm                          0.1.4
contourpy                     1.1.1
cryptography                  41.0.3
cycler                        0.12.1
debugpy                       1.6.7
decorator                     5.1.1
exceptiongroup                1.1.3
executing                     2.0.1
filelock                      3.9.0
fonttools                     4.43.1
fsspec                        2023.12.2
gmpy2                         2.1.2
huggingface-hub               0.20.1
idna                          3.4
importlib-metadata            6.8.0
ipykernel                     6.26.0
ipython                       8.16.1
jedi                          0.19.1
Jinja2                        3.1.2
joblib                        1.3.2
jupyter_client                8.5.0
jupyter_core                  5.3.0
kiwisolver                    1.4.5
macholib                      1.16.3
MarkupSafe                    2.1.1
matplotlib                    3.8.0
matplotlib-inline             0.1.6
mpmath                        1.3.0
nest-asyncio                  1.5.8
networkx                      3.1
numexpr                       2.8.7
numpy                         1.26.0
packaging                     23.2
pandas                        2.1.1
parso                         0.8.3
pexpect                       4.8.0
pickleshare                   0.7.5
Pillow                        10.0.1
pip                           23.3.2
platformdirs                  3.11.0
prompt-toolkit                3.0.39
protobuf                      3.20.3
psutil                        5.9.0
ptyprocess                    0.7.0
pure-eval                     0.2.2
pycparser                     2.21
Pygments                      2.16.1
pyinstaller                   6.3.0
pyinstaller-hooks-contrib     2023.10
PyMySQL                       1.1.0
pyOpenSSL                     23.2.0
pyparsing                     3.1.1
PySocks                       1.7.1
python-dateutil               2.8.2
pytz                          2023.3.post1
PyYAML                        6.0.1
pyzmq                         25.1.0
regex                         2023.10.3
requests                      2.31.0
safetensors                   0.4.1
scikit-learn                  1.3.2
scipy                         1.11.3
seaborn                       0.13.0
setuptools                    69.0.3
six                           1.16.0
stack-data                    0.6.2
sympy                         1.11.1
tensorboardX                  2.2
threadpoolctl                 3.2.0
tokenizers                    0.15.0
torch                         2.0.1
torchvision                   0.15.2a0
tornado                       6.3.3
tqdm                          4.66.1
traitlets                     5.13.0
transformers                  4.36.2
typing_extensions             4.7.1
tzdata                        2023.3
urllib3                       1.26.18
wcwidth                       0.2.9
wheel                         0.41.2
xformer                       1.0.1
zipp                          3.17.0
解决方案

1. 卸载错误安装的xformer

先清理冲突包:

pip uninstall -y xformer

2. 安装编译依赖(macOS环境)

xformers编译需要C++构建工具,在macOS上安装Xcode命令行工具:

xcode-select --install

若已安装,重置确保版本最新:

sudo xcode-select --reset

3. 安装匹配PyTorch版本的预编译xformers包

跳过源码编译,直接安装与PyTorch 2.0.1兼容的预编译版本:

pip install xformers==0.0.22.post7 --force-reinstall

4. 若需源码编译,补充依赖

如果必须源码编译,先安装编译工具依赖:

pip install ninja setuptools_scm

再重新尝试安装:

pip install xformers --no-cache-dir

5. 尝试conda安装

使用conda环境的话,可尝试从conda-forge源安装:

conda install -c conda-forge xformers

内容的提问来源于stack exchange,提问作者Ferry Liu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 21:44:53