Cannot install pyfftw3 by pip

2.5k Views Asked by At

I am trying using FFTW3 in python and when I try to install it I got this:

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/[email protected]/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

I have the newest version of python installed by Homebrew. Pip is also the newest version. I have tried pip install -U setuptools


Inspired by 'Swetank Poddar': I found the pyfftw3 is a python2 library, so I tried pip3 install pyfftw. But, I got a new question:

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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/3.9.1_6/Frameworks/Python.framework/Versions/3.9/include/python3.9/pyfftw Check the logs for full command output.

It looks like the problem is mainly about the "Building wheel for pyfftw".

4

There are 4 best solutions below

4
On

Alternatively you could install pyFFTW: pip install pyFFTW

Install instructions for Mac OS:
Install FFTW from homebrew:

brew install fftw

Set temporary environmental variables, such that pyfftw finds fftw:

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

Now install pyfftw from pip:

pip install pyfftw

It has been suggested that macports might also work fine. You should then replace the LD environmental variables above with the right ones.

  • DYLD - path for libfftw3.dylib etc - find /usr -name libfftw3.dylib
  • LDFLAGS - path for fftw3.h - find /usr -name fftw3.h
0
On

check the python version once ,by typing python --version and if it is the latest version of python go to the code that you are typing and check the print statement as it is showing error in command prompt as you mentioned...in latest version of python you have to use parenthesis after print("you have to use parenthesis")

0
On

For MacBook Air @ M1 a mix of instructions helped me:

  1. brew install fftw

  2. Find locations of libfftw3.dylib and fftw3.h and set environmental variables

    Example:

export DYLD_LIBRARY_PATH=/opt/homebrew/lib
export LDFLAGS="-L/opt/homebrew/include"
export CFLAGS="-I/usr/local/include"
  1. Clone pyFFTW repo

    git clone [email protected]:pyFFTW/pyFFTW.git

  2. Install pyFFTW

    CFLAGS="-Wno-implicit-function-declaration" pip install -e . -v

Links:

0
On

Refer to https://github.com/pyFFTW/pyFFTW/issues/303

  1. Run brew install fftw

  2. Install the lib with LDFLAGS="-L/usr/local/lib" CFLAGS="-I/usr/local/include -Wno-error=implicit-function-declaration" python setup.py install