[Numpy-discussion] Fortran & distutils on Mac OS X -- interactive mode?

Erik Sherwood sherwood at cam.cornell.edu
Sun Nov 19 11:23:56 CST 2006


Hi all,

I am using scipy-0.5.1 and numpy-1.0 on Mac OS X 10.4.8 (MacBook Pro  
late 2006) built with fink. I have code (I'm developing for the  
PyDSTool project) which uses numpy.distutils to build a .so file  
which is then loaded into python. When only C compilers are needed,  
everything runs as I expect, but when I need to build with fortran  
compilers (g95 in this case; there is no g77 built for the Intel macs  
yet), I get sent to interactive mode:

========================================================================
Starting interactive session
------------------------------------------------------------------------

Tasks:
   i       - Show python/platform/machine information
   ie      - Show environment information
   c       - Show C compilers information
   c<name> - Set C compiler (current:None)
   f       - Show Fortran compilers information
   f<name> - Set Fortran compiler (current:None)
   e       - Edit proposed sys.argv[1:].

Task aliases:
   0         - Configure
   1         - Build
   2         - Install
   2<prefix> - Install with prefix.
   3         - Inplace build
   4         - Source distribution
   5         - Binary distribution

Proposed sys.argv = ['SLIP_2D_pdc.py']

Choose a task (^D to quit, Enter to continue with setup):

I can just hit enter and things run as I like them to, more or less:
------------------------------------------------------------------------
customize AbsoftFCompiler
customize IbmFCompiler
Could not locate executable g77
Could not locate executable f77
Could not locate executable gfortran
Could not locate executable f95
customize GnuFCompiler
customize Gnu95FCompiler
customize G95FCompiler
customize G95FCompiler
customize G95FCompiler using build_clib
building 'radau5' library
compiling Fortran sources
Fortran f77 compiler: g95 -ffixed-form -fno-second-underscore -O3 - 
funroll-loops
Fortran f90 compiler: g95 -fno-second-underscore -O3 -funroll-loops
Fortran fix compiler: g95 -ffixed-form -fno-second-underscore -O3 - 
funroll-loops
creating /Users/sherwood/Apps/PyDSTool/tests/radau5_temp/Users
creating /Users/sherwood/Apps/PyDSTool/tests/radau5_temp/Users/sherwood
creating /Users/sherwood/Apps/PyDSTool/tests/radau5_temp/Users/ 
sherwood/Apps
creating /Users/sherwood/Apps/PyDSTool/tests/radau5_temp/Users/ 
sherwood/Apps/PyDSTool
creating /Users/sherwood/Apps/PyDSTool/tests/radau5_temp/Users/ 
sherwood/Apps/PyDSTool/integrator
compile options: '-c'
g95:f77: /Users/sherwood/Apps/PyDSTool/integrator/radau5.f
....

The code that uses distutils looks like this (radau5 refers to the  
fortran code I'm compiling):

if not (all([os.path.isfile(os.path.join(self._compilation_tempdir,
                    sf)) for sf in ['radau5'+self._vf_filename_ext 
+'_wrap.o',
                                    'lib_radau5'+self._vf_filename_ext 
+'.a',
                                    'radau5'+self._vf_filename_ext 
+'.py',
                                    '_radau5'+self._vf_filename_ext 
+'.def']])):
             modfilelist = [swigfile]
         else:
             modfilelist = []
         modfilelist.extend([radwrapfile, vffile, integfile, eventfile,
                            interfacefile, memfile])
         modfilelist.extend(libsources)
         fortfilelist=[radfile, lapackcfile, dc_lapackfile, lapackfile]
         # would like temp dir to be '/' but scipy_distutils cannot  
build the
         # radau library in that configuration (unlike Dopri's  
identical use of
         # regular python distutils, which cannot deal with Fortran  
sources).
         script_args = ['-q', 'build', '--build-lib='+os.getcwd(),
                  '-t'+self._compilation_tempdir,
                  '--build-base='+self._compilation_tempdir,
                  '--build-platlib='+os.getcwd(), '--build- 
purelib='+os.getcwd()]
         if self._compiler != '':
             script_args.append('-c'+str(self._compiler))
         # include directories for libraries
	narraydir = npy.get_numarray_include()
	npydir = npy.get_include()
         incdirs = [npydir, narraydir, os.getcwd(),  
self._compilation_tempdir,
                    self._compilation_sourcedir]
         incdirs.extend(libdirs)
         radlibdirs = [self._compilation_sourcedir,  
self._compilation_tempdir,
                        os.getcwd()]
         # Use distutils to perform the compilation of the selected  
files
        try:
             distobject = setup(name = "Radau5 integrator",
                   author = "PyDSTool (automatically generated)",
                   script_args = script_args,
                   ext_modules = [Extension 
("_radau5"+self._vf_filename_ext,
                                  sources=modfilelist,
                                  include_dirs=incdirs,
                                  library_dirs=radlibdirs+['./'],
                                  libraries=['radau5'],
                                  extra_compile_args=['-w', '- 
D__RADAU__'],
                                  extra_link_args=['-w'])],
                   	libraries=[('radau5',{'sources': fortfilelist,
                               'library_dirs': radlibdirs+['./']})])


I would like to be able to skip the interactive mode -- how should I  
invoke distutils to skip all of the interaction and go straight to  
compilation?

Thanks,

Erik Sherwood
Center for Applied Mathematics	|	Phone: 	(607) 255-4195
657 Rhodes Hall					|	Fax:		(607) 255-9860
Cornell University				|	Email:	sherwood at cam.cornell.edu
Ithaca, NY 14853					|	Web:	http://www.cam.cornell.edu/~sherwood





More information about the Numpy-discussion mailing list