无法在 Macos M1 中使用 python 3.9 安装 pyFFTW

Can't install pyFFTW with python 3.9 in Macos M1

知道如何解决这个问题吗? 我真的需要将 pyfftw 安装到 conda 环境中,该环境已经具有我需要的其他库,例如 tensorflow。直到知道,我只能为 python 3.9 正确安装其他库(即 tensorflow)。 我正在研究 Mac M1。 这是命令 pip install pyfftw:

的错误输出
    Collecting pyfftw
  Using cached pyFFTW-0.12.0.tar.gz (137 kB)
Requirement already satisfied: numpy<2.0,>=1.10 in /Users/mymac/miniforge3/envs/tf/lib/python3.9/site-packages (from pyfftw) (1.19.5)
Building wheels for collected packages: pyfftw
  Building wheel for pyfftw (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /Users/mymac/miniforge3/envs/tf/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-5kpcegg9/pyfftw_56df32e267e3416fb4e9f01e6282e505/setup.py'"'"'; __file__='"'"'/private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-5kpcegg9/pyfftw_56df32e267e3416fb4e9f01e6282e505/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-wheel-6urq200p
       cwd: /private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-5kpcegg9/pyfftw_56df32e267e3416fb4e9f01e6282e505/
  Complete output (25 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-11.0-arm64-3.9
  creating build/lib.macosx-11.0-arm64-3.9/pyfftw
  copying pyfftw/config.py -> build/lib.macosx-11.0-arm64-3.9/pyfftw
  copying pyfftw/_version.py -> build/lib.macosx-11.0-arm64-3.9/pyfftw
  copying pyfftw/__init__.py -> build/lib.macosx-11.0-arm64-3.9/pyfftw
  creating build/lib.macosx-11.0-arm64-3.9/pyfftw/builders
  copying pyfftw/builders/builders.py -> build/lib.macosx-11.0-arm64-3.9/pyfftw/builders
  copying pyfftw/builders/__init__.py -> build/lib.macosx-11.0-arm64-3.9/pyfftw/builders
  copying pyfftw/builders/_utils.py -> build/lib.macosx-11.0-arm64-3.9/pyfftw/builders
  creating build/lib.macosx-11.0-arm64-3.9/pyfftw/interfaces
  copying pyfftw/interfaces/cache.py -> build/lib.macosx-11.0-arm64-3.9/pyfftw/interfaces
  copying pyfftw/interfaces/__init__.py -> build/lib.macosx-11.0-arm64-3.9/pyfftw/interfaces
  copying pyfftw/interfaces/scipy_fft.py -> build/lib.macosx-11.0-arm64-3.9/pyfftw/interfaces
  copying pyfftw/interfaces/dask_fft.py -> build/lib.macosx-11.0-arm64-3.9/pyfftw/interfaces
  copying pyfftw/interfaces/numpy_fft.py -> build/lib.macosx-11.0-arm64-3.9/pyfftw/interfaces
  copying pyfftw/interfaces/scipy_fftpack.py -> build/lib.macosx-11.0-arm64-3.9/pyfftw/interfaces
  copying pyfftw/interfaces/_utils.py -> build/lib.macosx-11.0-arm64-3.9/pyfftw/interfaces
  UPDATING build/lib.macosx-11.0-arm64-3.9/pyfftw/_version.py
  set build/lib.macosx-11.0-arm64-3.9/pyfftw/_version.py to '0.12.0'
  running build_ext
  error: Could not find the FFTW header 'fftw3.h'
  ----------------------------------------
  ERROR: Failed building wheel for pyfftw
  Running setup.py clean for pyfftw
Failed to build pyfftw
Installing collected packages: pyfftw
    Running setup.py install for pyfftw ... error
    ERROR: Command errored out with exit status 1:
     command: /Users/mymac/miniforge3/envs/tf/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-5kpcegg9/pyfftw_56df32e267e3416fb4e9f01e6282e505/setup.py'"'"'; __file__='"'"'/private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-5kpcegg9/pyfftw_56df32e267e3416fb4e9f01e6282e505/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-record-qt54h1vj/install-record.txt --single-version-externally-managed --compile --install-headers /Users/mymac/miniforge3/envs/tf/include/python3.9/pyfftw
         cwd: /private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-5kpcegg9/pyfftw_56df32e267e3416fb4e9f01e6282e505/
    Complete output (7 lines):
    running install
    running build
    running build_py
    UPDATING build/lib.macosx-11.0-arm64-3.9/pyfftw/_version.py
    set build/lib.macosx-11.0-arm64-3.9/pyfftw/_version.py to '0.12.0'
    running build_ext
    error: Could not find the FFTW header 'fftw3.h'
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/mymac/miniforge3/envs/tf/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-5kpcegg9/pyfftw_56df32e267e3416fb4e9f01e6282e505/setup.py'"'"'; __file__='"'"'/private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-5kpcegg9/pyfftw_56df32e267e3416fb4e9f01e6282e505/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-record-qt54h1vj/install-record.txt --single-version-externally-managed --compile --install-headers /Users/mymac/miniforge3/envs/tf/include/python3.9/pyfftw Check the logs for full command output.

PyPA 没有为 osx-arm64 提供预编译的轮子,因此它是从源代码构建的。根据the documentation,构建源代码时,需要先安装FFTW。幸运的是,Conda Forge 似乎正在构建这个(包括 osx-arm64),所以尝试

conda install -c conda-forge fftw

pip install pyfftw

否则,我放弃了 an issue to the Conda Forge feedstock,并指出他们应该能够构建 osx-arm64 构建。希望这会向前发展,将来可以完全避免 Pip 和本地编译。

更新:现在正在为 osx-arm64 构建原料,因此您应该能够使用

conda install -c conda-forge pyfftw