3

I am relatively new to python. I am using Enthought Canopy for my work. After importing f2py from numpy, I keep on running into the invalid syntax error when trying to execute:

f2py -m (modname) -c --fcompiler=gfortran (prog.f90)

Needless to say, I have gfortran installed, and the program is present in the working directory. Even trying to run

f2py -c --help-fcompiler

as recommended somewhere on the net leads to an error saying : name 'c' is not defined. On typing f2py:

module 'numpy.f2py' from 'C:\Users\acer\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.0.3.1262.win-x86_64\lib\site-packages\numpy\f2py\__init__.pyc'

which indicates that f2py is installed. Could anyone have an idea where I am going wrong?

zero323
  • 322,348
  • 103
  • 959
  • 935
Aves
  • 43
  • 4
  • You say you're "importing f2py from numpy"? That could be the problem right there. f2py is a command line tool, not a python module. Try running the commands in a terminal. You may have to find the directory where f2py is installed (in a normal Python install it would be in the Scripts folder, I have no idea where it would be in Canopy) and make sure it is in your path. Depending on how your system is set up you may need to run something like `Python f2py.py` instead of `f2py` – IanH Sep 21 '13 at 02:55
  • I located the directory containing f2py and tried running it from command line but I ran into an error which ends with : `ValueError: [u'path']` The traceback usually starts when f2py is compiling. Besides, isn't there be anyway to access f2py from the root of the command line or the Ipython interface? – Aves Sep 21 '13 at 10:27
  • The ValueError looks very much like the distutils issue while trying to start compiling with MSVC in an unproperly configured environment. Can you use the compiler on the command line independently of Python? – dpinte Sep 21 '13 at 13:25
  • The error apparently sprouted from me defining (erroneously) one path in my environment variables to `g77` as a compiler and another to `gfortran`. After I sorted that out, trying out running with f2py.py in the scripts folder worked. – Aves Sep 21 '13 at 17:15

1 Answers1

0

You can try running the following command in the directory where your script is doing:

on Windows

python path_to_scripts\f2py.py -c -m module_name prog.f90 --fcompiler=gfortran

on Linux

python path_to_scripts/f2py.py -c -m module_name prog.f90 --fcompiler=gfortran

Where path_to_scripts is the path to the Scripts directory. For example: C:\Python27\Scripts. In case of Canopy you have to look where this directory is...

Saullo G. P. Castro
  • 56,802
  • 26
  • 179
  • 234
  • This, along with sorting out some conflicting definitions between linker and compiler paths did the trick. Thanks! – Aves Sep 21 '13 at 17:13