0

I wish to install a part from the quite outdated Python-Code in 'Principles of Planetary Climate' from Pierrehumbert. For this part gfortran compiler is needed. I once installed gcc. I think it installed gfortran, too (see text from my terminal below). But after the required command according Pierrehumbert 'python setup.py build --lite' I got an error: 'sh: f2py: command not found' Honestly I have no clue what to do next. I'm and remain a rookie in this field of the dependency hell.

Meanwhile I learned: 'The purpose of the F2PY –Fortran to Python interface generator– utility is to provide a connection between Python and Fortran. F2PY is a part of NumPy (numpy.f2py) and also available as a standalone command line tool.' Pierrehumbert's code used numpy 1.17 (I guess). My numpy version is 1.24.3. I had to find a workaround: Pierrehumbert uses numpy.float that doesn't work with numpy 1.24.3. I had to replace it with numpy.float64. With this a great part of Pierrehumbert's code works. Is it possible that Pierrehumbert's code uses an outdated f2py that numpy 1.24.3 doesn't recognise? What is the solution? I really have no clue.

Last login: Mon May  1 19:55:58 on ttys000
widmerhans@Mac-mini-2 ~ % cd /Users/widmerhans/Documents/Python_PRINCIPLES_OF_PLANETARY_CLIMATE_Buch/PlanetaryClimateCourseware/CliMT-master
widmerhans@Mac-mini-2 CliMT-master % python setup.py build --lite
Found executable /usr/local/bin/gfortran
Using gnu95 compiler
src/grid
['src/grid/Driver.f90']

 Building _grid.so ... 

sh: f2py: command not found
f2py -c -m _grid --fcompiler=gnu95 --noopt -Isrc/grid -Isrc/grid/include -Isrc/grid/src -Isrc/grid/src/include --f77flags="-DIM=1 -DJM=1 -DKM=30 -ffixed-line-length-132 -fdefault-real-8" --f90flags="-DIM=1 -DJM=1 -DKM=30 -fdefault-real-8 -fno-range-check -ffree-form" _grid.pyf src/grid/Driver.f90 src/grid/src/dimensions.F90
sh: f2py: command not found
+++ Compilation failed
widmerhans@Mac-mini-2 CliMT-master % 
  • Command not found simply means that the systom cannot find command `f2py`. Do you have f2py installed? If not, install it. Where do you have your Python from? – Vladimir F Героям слава May 02 '23 at 05:27
  • Thanks. It seems my problem is similar to https://stackoverflow.com/questions/30000857/install-f2py-with-python3. But I didn't understand the solution. I'm lost. – widmerhans May 02 '23 at 10:35
  • I used 'import numpy.f2py' in a test Python file. There was no error message. I assume f2py was installed on my system. – widmerhans May 02 '23 at 11:43
  • Try executing `f2py` on the command line. It is a normal command. – Vladimir F Героям слава May 02 '23 at 13:31
  • Please read the description of the tags you are adding. Tag [tag:python-3.x] says *"DO NOT USE UNLESS YOUR QUESTION IS FOR PYTHON 3 ONLY. Always use alongside the standard [python] tag."* – Vladimir F Героям слава May 02 '23 at 14:13
  • How? Just typing 'f2py' in the command line didn't work: 'zsh: command not found: f2py'. Should I try 'python -m numpy.f2py'? I don't know what this command would evoke. I don't want to disrupt numpy or so. How to install f2py if it is not installed. Did you read my above stackoverflow link? It looks not so simple with Python 3. Is there a command 'pip3 install f2py' or so? – widmerhans May 02 '23 at 14:27
  • f2py is a normal command, if you o not have it, you most likely have to install f2py. I have now also opened your link. Did you try `f2py3`? Try searching for an `f2py` or `f2py3` executable in your system. I do not know how it is installed on mac. – Vladimir F Героям слава May 02 '23 at 15:03
  • On https://pypi.org/project/F2PY/#description I found that 'F2PY 2.45.241_1926' is the latest version (2005). & the remark: 'IMPORTANT: F2PY is now part of NumPy project. Installing numpy will be sufficient.' No hint how to install. & in terminal 'zsh: command not found: f2py3'. I quit. I'm too stupid for this stuff. Thanks anyway! – widmerhans May 02 '23 at 15:26

0 Answers0