Posts Tagged ‘brew’

Installing and running fmmlib from MATLAB on Mac OS X

Tuesday, December 26th, 2017

No better way to finish 2017 than trying to compile some old fortran code. This time it’s the fast multipole method library from nyu, fmmlib.

Here’s how I did it on a MacBook Pro running OS X 10.12 with MATLAB r2018a pre-release.

First install gfortran using homebrew via:

brew install gcc

Now we need to convince to use find and use gfortran.

Download gfortran.xml

and

Download gfortran.xml

In MATLAB issue:

copyfile('~/Downloads/xcode7_mexopts/gfortran.xml',fullfile( matlabroot, 'bin', 'maci64', 'mexopts' ))

On the command line, install gfortrani8 in the same directory as gfortran. I did this via:

cp ~/Downloads/gfortrani8 /usr/local/Cellar/gcc/7.2.0/bin/gfortrani8

Now, the following should succeed in MATLAB to setup the gfortran compiler:

mex -setup -v FORTRAN

For posterity: If you get “sdk” related issues, you may need to copy all the 10.13 lines in gfortran.xml and create analogous lines for 10.14 etc.

It seems like the '-compatibleArrayDims' flag should be used with fmmlib, but honestly I’m not sure. Something to revisit if it crashes on giant input I guess.

Finally, I had trouble locating the libgfortran.a library and convincing MATLAB’s Mex to use it. Therefore, I added:

[~,libgfortran] = system('gfortran -print-file-name=libgfortran.dylib');
libgfortran = libgfortran(1:end-1);

to my Mex script so that I can issue lines like this:

mex('fmm3d_r2012a.c',fortran_object_files{:},libgfortran);

This is enough to compile all of the fortran source files one by one and then link them during compilation and linking of the fmm3d_r2012a.c file.

I’ve added a matlab/compile.m script to my GitHub mirror/fork of the fmmlib library. So if you do the steps above you should be to just issue:

cd ~/Downloads
git clone 
cd ~/Downloads/fmmlib3d-1.2/matlab/
compile

Source

Linker error on freshly brewed python install

Wednesday, May 18th, 2016
from PIL import Image
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/PIL/Image.py", line 119, in <module>
    import io
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
  Referenced from: /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
  Expected in: flat namespace
 in /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so

Apparently this is happening because bash was still confused about which python to use after brew install python. I issued:

hash -r python

to fix the problem. But just using a new shell would also work.

Unknown locale error on freshly brewed python

Wednesday, May 18th, 2016
    import matplotlib.path
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1131, in <module>
    rcParams = rc_params()
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 975, in rc_params
    return rc_params_from_file(fname, fail_on_error)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1100, in rc_params_from_file
    config_from_file = _rc_params_in_file(fname, fail_on_error)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1018, in _rc_params_in_file
    with _open_file_or_url(fname) as fd:
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1000, in _open_file_or_url
    encoding = locale.getdefaultlocale()[1]
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 543, in getdefaultlocale
    return _parse_localename(localename)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 475, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

I fixed this by adding

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8