【问题标题】:Cannot install pyfftw3 by pip无法通过 pip 安装 pyfftw3
【发布时间】:2021-01-27 13:48:53
【问题描述】:

我正在尝试在 python 中使用 FFTW3,当我尝试安装它时,我得到了这个:

xxxxxxx@iMac ~ % pip3 install pyfftw3      
Collecting pyfftw3
  Using cached PyFFTW3-0.2.1.tar.gz (25 kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/local/opt/python@3.9/bin/python3.9 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-install-m021xxq5/pyfftw3_69a9370f7f41441eaca6ae508a6a1544/setup.py'"'"'; __file__='"'"'/private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-install-m021xxq5/pyfftw3_69a9370f7f41441eaca6ae508a6a1544/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-pip-egg-info-m06gikf1
         cwd: /private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-install-m021xxq5/pyfftw3_69a9370f7f41441eaca6ae508a6a1544/
    Complete output (6 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-install-m021xxq5/pyfftw3_69a9370f7f41441eaca6ae508a6a1544/setup.py", line 81
        print "build %s from template %s" %(outfile, tmplfile)
              ^
    SyntaxError: invalid syntax
    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/58/07/e070b9a44429bbd5481f9f0b2d1b35d896fbfd180051e05c840186a31c8a/PyFFTW3-0.2.1.tar.gz#sha256=8941a023e6e4f501e7cec92382c3d3f76f47c7583e9eade738840dd9e4e467c4 (from https://pypi.org/simple/pyfftw3/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement pyfftw3
ERROR: No matching distribution found for pyfftw3

我有 Homebrew 安装的最新版本的 python。 Pip 也是最新版本。 我试过pip install -U setuptools


受“Swetank Poddar”的启发:我发现pyfftw3 是一个python2 库,所以我尝试了pip3 install pyfftw。但是,我有一个新问题:

Collecting pyfftw
  Downloading pyFFTW-0.12.0.tar.gz (137 kB)
     |████████████████████████████████| 137 kB 167 kB/s 
Requirement already satisfied: numpy<2.0,>=1.10 in /usr/local/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: /usr/local/opt/python@3.9/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-install-p3twpksg/pyfftw_a5a93b1d21cd45bb90489634e47c82a5/setup.py'"'"'; __file__='"'"'/private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-install-p3twpksg/pyfftw_a5a93b1d21cd45bb90489634e47c82a5/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-wheel-e51wsh5k
       cwd: /private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-install-p3twpksg/pyfftw_a5a93b1d21cd45bb90489634e47c82a5/
  Complete output (25 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.15-x86_64-3.9
  creating build/lib.macosx-10.15-x86_64-3.9/pyfftw
  copying pyfftw/config.py -> build/lib.macosx-10.15-x86_64-3.9/pyfftw
  copying pyfftw/_version.py -> build/lib.macosx-10.15-x86_64-3.9/pyfftw
  copying pyfftw/__init__.py -> build/lib.macosx-10.15-x86_64-3.9/pyfftw
  creating build/lib.macosx-10.15-x86_64-3.9/pyfftw/builders
  copying pyfftw/builders/builders.py -> build/lib.macosx-10.15-x86_64-3.9/pyfftw/builders
  copying pyfftw/builders/__init__.py -> build/lib.macosx-10.15-x86_64-3.9/pyfftw/builders
  copying pyfftw/builders/_utils.py -> build/lib.macosx-10.15-x86_64-3.9/pyfftw/builders
  creating build/lib.macosx-10.15-x86_64-3.9/pyfftw/interfaces
  copying pyfftw/interfaces/cache.py -> build/lib.macosx-10.15-x86_64-3.9/pyfftw/interfaces
  copying pyfftw/interfaces/__init__.py -> build/lib.macosx-10.15-x86_64-3.9/pyfftw/interfaces
  copying pyfftw/interfaces/scipy_fft.py -> build/lib.macosx-10.15-x86_64-3.9/pyfftw/interfaces
  copying pyfftw/interfaces/dask_fft.py -> build/lib.macosx-10.15-x86_64-3.9/pyfftw/interfaces
  copying pyfftw/interfaces/numpy_fft.py -> build/lib.macosx-10.15-x86_64-3.9/pyfftw/interfaces
  copying pyfftw/interfaces/scipy_fftpack.py -> build/lib.macosx-10.15-x86_64-3.9/pyfftw/interfaces
  copying pyfftw/interfaces/_utils.py -> build/lib.macosx-10.15-x86_64-3.9/pyfftw/interfaces
  UPDATING build/lib.macosx-10.15-x86_64-3.9/pyfftw/_version.py
  set build/lib.macosx-10.15-x86_64-3.9/pyfftw/_version.py to '0.12.0'
  running build_ext
  error: Could not find any of the FFTW libraries
  ----------------------------------------
  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: /usr/local/opt/python@3.9/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-install-p3twpksg/pyfftw_a5a93b1d21cd45bb90489634e47c82a5/setup.py'"'"'; __file__='"'"'/private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-install-p3twpksg/pyfftw_a5a93b1d21cd45bb90489634e47c82a5/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-record-ljyxfo00/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/Cellar/python@3.9/3.9.1_6/Frameworks/Python.framework/Versions/3.9/include/python3.9/pyfftw
         cwd: /private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-install-p3twpksg/pyfftw_a5a93b1d21cd45bb90489634e47c82a5/
    Complete output (7 lines):
    running install
    running build
    running build_py
    UPDATING build/lib.macosx-10.15-x86_64-3.9/pyfftw/_version.py
    set build/lib.macosx-10.15-x86_64-3.9/pyfftw/_version.py to '0.12.0'
    running build_ext
    error: Could not find any of the FFTW libraries
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/opt/python@3.9/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-install-p3twpksg/pyfftw_a5a93b1d21cd45bb90489634e47c82a5/setup.py'"'"'; __file__='"'"'/private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-install-p3twpksg/pyfftw_a5a93b1d21cd45bb90489634e47c82a5/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/xc/vzy2gb2j2hs8tyv7j70d979h0000gn/T/pip-record-ljyxfo00/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/Cellar/python@3.9/3.9.1_6/Frameworks/Python.framework/Versions/3.9/include/python3.9/pyfftw Check the logs for full command output.

看起来问题主要是关于“pyfftw的构建轮”。

【问题讨论】:

  • 这看起来像一个 python2 库。尝试使用pip 而不是pip3(假设您安装了python 2)
  • 感谢您的建议,我在link 上搜索了pyfftw,它显示pyfftw3 是python2 库,pyfftw 是python3 库,但是我在安装@987654332 时遇到了一个新问题@。请看看我编辑的问题。
  • pyfftw 是一个围绕 FFTW 库的 python 包装器。您需要下载这些库并更新您的 env 值(应该在 PYFFTW 文档中提及)
  • 目前没有用于 Python 3.9 的预构建二进制文件,因此您要么必须自己构建它,要么可能更容易使用,比如 Python 3.8,在这种情况下安装应该只是工作,否则你可以等到支持 3.9。

标签: python installation pip pyfftw


【解决方案1】:

或者你可以安装pyFFTW:pip install pyFFTW

Install instructions for Mac OS:
从自制软件安装 FFTW:

brew install fftw

设置临时环境变量,让pyfftw找到fftw:

export DYLD_LIBRARY_PATH=/usr/local/lib export LDFLAGS="-L/usr/local/lib"
export CFLAGS="-I/usr/local/include"

现在从 pip 安装 pyfftw:

pip install pyfftw

有人建议 macports 也可以正常工作。然后,您应该用正确的替换上面的 LD 环境变量。

  • DYLD - libfftw3.dylib 等的路径 - 查找 /usr -name libfftw3.dylib
  • LDFLAGS - fftw3.h 的路径 - 查找 /usr -name fftw3.h

【讨论】:

  • 谢谢,你是对的。但是当我尝试安装pyfftw时遇到了一个新问题
  • 我更新了我的答案以获取更多信息,请访问GitHub repo of pyFFTW
  • 我无法在我的 Mac M1 中完成这项工作。错误:找不到 FFTW 标头 'fftw3.h' ------------------------- --- 错误:pyfftw 构建*失败
  • 你试过these steps吗?即使报告问题的人没有使用苹果硅胶,也有关于如何为 M1 Mac 安装 pyfftw 的说明。
【解决方案2】:

通过键入 python --version 检查一次 python 版本,如果它是最新版本的 python,请转到您正在输入的代码并检查 print 语句,因为它显示错误正如您提到的命令提示符...在最新版本的python中,您必须在 print("you have to use parenthesis") 后使用括号

【讨论】:

    【解决方案3】:

    参考https://github.com/pyFFTW/pyFFTW/issues/303

    1. 运行brew install fftw

    2. 使用LDFLAGS="-L/usr/local/lib" CFLAGS="-I/usr/local/include -Wno-error=implicit-function-declaration" python setup.py install安装库

    【讨论】: