[SciPy-dev] scipy on macos x works

Jeff Whitaker jsw at cdc.noaa.gov
Wed Mar 6 06:49:08 CST 2002


Hi:  I've suceeded in getting scipy to work on MacOS X 10.1.3 (well mostly
- it fails a few tests).  Here are the patches I used to get it working.

1) f2py

--- F2PY-2.13.175-1212/src/fortranobject.h.orig Mon Mar  4 20:12:46 2002
+++ F2PY-2.13.175-1212/src/fortranobject.h      Mon Mar  4 20:16:36 2002
@@ -12,7 +12,9 @@
 #undef F2PY_REPORT_ATEXIT
 #else
 #ifndef __WIN32__
+#ifndef __APPLE__
 #define F2PY_REPORT_ATEXIT
+#endif
 #endif
 #endif

This prevents undefined symbol errors for "ftime" and "on_exit", which
don't exist on MacOS X.

2)  python 2.2

--- Python-2.2/Lib/distutils/util.py    Sat Feb 23 21:23:17 2002
+++ Python-2.2/Lib/distutils/util.py    Sat Feb 23 21:24:31 2002
@@ -41,6 +41,11 @@
     # Try to distinguish various flavours of Unix

     (osname, host, release, version, machine) = os.uname()
+
+    # On MacOS X, remove space from machine name
+
+    if machine == "Power Macintosh":
+       machine = "PowerMacintosh"

     # Convert the OS name to lowercase and remove '/' characters
     # (to accommodate BSD/OS)

If the temporary build directory has spaces in the name, the scipy install
chokes.

--- Python-2.2/configure.orig   Sun Mar  3 13:02:32 2002
+++ Python-2.2/configure        Tue Mar  5 04:38:52 2002
@@ -3174,13 +3174,10 @@
                        LDSHARED="$LDSHARED -undefined suppress"
                fi ;;
        Darwin/*)
-               LDSHARED='$(CC) $(LDFLAGS) -bundle'
+               LDSHARED='$(CC) $(LDFLAGS) -bundle -bundle_loader
/sw/bin/python.exe'
                if test "$enable_framework" ; then
                        # Link against the framework. All externals should
be de
fined.
                        LDSHARED="$LDSHARED "'-framework
$(PYTHONFRAMEWORK)'
-               else
-                       # No framework. Ignore undefined symbols, assuming
they
come from Python
-                       LDSHARED="$LDSHARED -flat_namespace -undefined
suppress"
                fi ;;
        Linux*) LDSHARED="gcc -shared";;
        dgux*) LDSHARED="ld -G";;

Replacing the LDSHARED flags "-flat_namespace -undefined suppress" with
"-bundle_loader <pythonprefix>/bin/python.<execsuffix>" makes extension
modules compile with "two-level namespaces".  What exactly this means I
can't tell you - this is a workaround for multiply defined symbol errors
that occur when multiple "flat namespace" loadable modules that link the
same static lib are loaded in python in Mac OS X.  This fix was suggested
to me on the pythonmac-sig list.

3) scipy

--- ./scipy/scipy_distutils/command/build_flib.py.orig	Sat Feb 23 07:42:12 2002
+++ ./scipy/scipy_distutils/command/build_flib.py	Sat Feb 23 13:26:32 2002
@@ -362,6 +362,9 @@
             cmd = 'ar -cur  %s %s' % (lib_file,objects)
             print cmd
             os.system(cmd)
+            cmd = 'ranlib %s ' % lib_file
+            print cmd
+            os.system(cmd)

     def build_library(self,library_name,source_list,module_dirs=None,
                       temp_dir = ''):
@@ -667,7 +670,7 @@

     def get_linker_so(self):
         # win32 linking should be handled by standard linker
-        if sys.platform != 'win32':
+        if sys.platform != 'win32' and os.uname()[0] != 'Darwin':
             return [self.f77_compiler,'-shared']

     def f90_compile(self,source_files,module_files,temp_dir=''):
--- ./scipy/sparse/UMFPACK2.2/Makefile.orig	Sat Feb 23 17:23:22 2002
+++ ./scipy/sparse/UMFPACK2.2/Makefile	Sat Feb 23 17:23:37 2002
@@ -33,6 +33,7 @@

 libumfpack.a: $(UMFD) $(UMFS) $(UMFC) $(UMFZ) $(HARWELL)
 	ar -rv libumfpack.a $(UMFD) $(UMFS) $(UMFC) $(UMFZ) $(HARWELL)
+	ranlib libumfpack.a

 dmain.out: dmain in
 	dmain < in > dmain.out
--- ./scipy/special/amos/setup.py.orig	Sat Feb 23 17:20:19 2002
+++ ./scipy/special/amos/setup.py	Sat Feb 23 17:20:51 2002
@@ -30,6 +30,9 @@
         cmd = 'ar -cr lib%s.a %s' % (library_name,objects)
         print cmd
         os.system(cmd)
+        cmd = 'ranlib lib%s.a' % library_name
+        print cmd
+        os.system(cmd)
     def build_library(self,library_name,source_list):

         object_list = map(lambda x: x[:-1] +'o',source_list)
--- ./scipy/special/cephes/polmisc.c.orig	Sat Feb 23 06:35:43 2002
+++ ./scipy/special/cephes/polmisc.c	Sat Feb 23 06:36:00 2002
@@ -4,7 +4,9 @@
  */

 #include <stdio.h>
+#ifndef __APPLE__
 #include <malloc.h>
+#endif
 #include "mconf.h"
 #ifndef ANSIPROT
 double atan2(), sqrt(), fabs(), sin(), cos();
--- ./scipy/special/cephes/polyn.c.orig	Sat Feb 23 06:36:21 2002
+++ ./scipy/special/cephes/polyn.c	Sat Feb 23 06:36:39 2002
@@ -65,7 +65,9 @@
 #define NULL 0
 #endif
 #include "mconf.h"
+#ifndef __APPLE__
 #include <malloc.h>
+#endif

 /* near pointer version of malloc() */
 /*
--- ./scipy/scipy_distutils/command/build_clib.py.orig	Sat Feb 23 20:21:51 2002
+++ ./scipy/scipy_distutils/command/build_clib.py	Sat Feb 23 20:24:48 2002
@@ -249,6 +249,9 @@
             self.compiler.create_static_lib(objects, lib_name,
                                             output_dir=self.build_clib,
                                             debug=self.debug)
+            cmd = 'ranlib %s/lib%s.a' % (self.build_clib,lib_name)
+            print cmd
+            os.system(cmd)

         # for libraries

--- scipy/special/cephes/mconf.h.orig	Tue Mar  5 10:01:37 2002
+++ scipy/special/cephes/mconf.h	Tue Mar  5 10:02:50 2002
@@ -100,7 +100,7 @@

 /* Intel IEEE, low order words come first:
  */
-#define IBMPC 1
+/* #define IBMPC 1*/

 /* Motorola IEEE, high order words come first
  * (Sun 680x0 workstation):
@@ -113,10 +113,10 @@
  * roundoff problems in pow.c:
  * (Sun SPARCstation)
  */
-/* #define UNK 1 */
+#define UNK 1

 /* If you define UNK, then be sure to set BIGENDIAN properly. */
-#define BIGENDIAN 0
+#define BIGENDIAN 1

 /* Define this `volatile' if your compiler thinks
  * that floating point arithmetic obeys the associative

Basically, this patch adds the execution of "ranlib" to the build scripts,
ifdef's out malloc.h includes (malloc.h doesn't exist on OS X), and tells
cephes that OS X is big endian.


You'll also need to install atlas, g77, fftw, numeric (linked to
atlas), and optionally wxpython-wxgtk (wxpython-wxmac doesn't yet work).
All of these packages are available through fink (http://fink.sf.net). I'm
a fink developer and am the maintainer for most of the scientific packages
(as well as python).  I've just uploaded a package for scipy (based on a
March 5 CVS snapshot).  It would be great if these patches could be
incorporated into f2py and scipy before the 0.2 release.  Hopefull, python
2.2.1 will contain the necessary changes to LDSHARED, although I don't
think it will remove the spaces from "osname".  Maybe there is a way to
work around this in scipy, but I couldn't figure it out.

Here are the results of scipy.test() on my G4:

Ran 262 tests in 9.809s

FAILED (failures=1, errors=1)
<unittest.TextTestRunner instance at 0x3f6f150>

the messages include:

!! FAILURE building test for  scipy.basic

/sw/src/root-scipy-20020305-1/sw/lib/python2.2/site-packages/scipy/basic1a.py:107:
AttributeError: 'module' object has no attribute 'standard_normal' (in
randn)

FAILURE to import scipy.stats.distributions
<string>:0: AttributeError: 'module' object has no attribute
'distributions' (in ?)
FAILURE to import scipy.stats.rv
<string>:0: AttributeError: 'module' object has no attribute 'rv' (in ?)
FAILURE to import scipy.stats.rv2
<string>:0: AttributeError: 'module' object has no attribute 'rv2' (in ?)
FAILURE to import scipy.stats.stats
<string>:0: AttributeError: 'module' object has no attribute 'stats' (in
?)

======================================================================
ERROR: check_basic (test_handy.test_real_if_close)
----------------------------------------------------------------------
Traceback (most recent call last):
  File
"/sw/src/root-scipy-20020305-1/sw/lib/python2.2/site-packages/scipy/tests/test_handy.py",
line 206, in check_basic
    a = randn(10)
  File
"/sw/src/root-scipy-20020305-1/sw/lib/python2.2/site-packages/scipy/basic1a.py",
line 107, in randn
AttributeError: 'module' object has no attribute 'standard_normal'

======================================================================
FAIL: check_basic (test_basic1a.test_roots)
----------------------------------------------------------------------
Traceback (most recent call last):
  File
"/sw/src/root-scipy-20020305-1/sw/lib/python2.2/site-packages/scipy/tests/test_basic1a.py",
line 19, in check_basic
    assert_array_almost_equal(roots(a1),[2,2],11)
  File
"/sw/src/root-scipy-20020305-1/sw/lib/python2.2/site-packages/scipy_test/scipy_test.py",
line 313, in assert_array_almost_equal
AssertionError:
Arrays are not almost equal:

Do people see these failures on linux, or is it something I should try to
fix for OS X?


Cheers,

-Jeff


 --
Jeffrey S. Whitaker         Phone  : (303)497-6313
Meteorologist               FAX    : (303)497-6449
NOAA/OAR/CDC  R/CDC1        Email  : jsw at cdc.noaa.gov
325 Broadway                Web    : www.cdc.noaa.gov/~jsw
Boulder, CO, USA 80303-3328 Office : Skaggs Research Cntr 1D-124




More information about the Scipy-dev mailing list