Configuring 3rd party python modules for use with CASA

Configuring 3rd party python modules for use with CASA

Postby jmarvil » Sat Nov 19, 2011 11:22 am

Since CASA runs in an interactive python session (ipython), it is entirely possible to add additional python modules beyond the basic ones included with CASA (e.g. numpy, scipy, matplotlib). The only trick is to build these modules from source using the version of python that is distributed with CASA Here, I give a short example of how I accomplished this using Mac OS X (the theory applies to any OS, but the paths will be different).

First, download the source for the package you want to install. I am going to use the 'mechanize' package, downloaded from here: http://wwwsearch.sourceforge.net/mechanize/

The installation instructions included with the mechanize package are the same as most other python packages:
1. download and untar the mechanize source code
2. cd into the directory containing the source, in this case, mechanize-0.2.5
3. from the terminal type: python setup.py install

however, following these instructions will only make mechanize available to the default version of python, ie. the one you would get by typing 'python' from the terminal. The trick here is to replace 'python' above with the full path of the version of python used by CASA. You can find the path that will work for you by typing:
>> !which python
into CASA

On my Mac, the path that worked for me was : /Applications/CASA.app/Contents/MacOS/python

So instead of (3) I typed:
sudo /Applications/CASA.app/Contents/MacOS/python setup.py install

after the configuration finished, I restarted CASA and verified that this worked by typing:
>> import mechanize
jmarvil
 
Posts: 8
Joined: Sat Nov 19, 2011 10:43 am

Re: Configuring 3rd party python modules for use with CASA

Postby akleroy » Thu Dec 08, 2011 9:37 am

Josh, this is a nice write-up. Would you mind if we steal it for the Python background that we've been putting together in the CASA guides to give a more permanent home?

http://casaguides.nrao.edu/index.php?ti ... onOverview

We've been using these pages as the material for a bi-weekly seminar for the local postdocs and graduate students (on its second run through).
akleroy
 
Posts: 2
Joined: Tue Jul 19, 2011 12:02 pm

Re: Configuring 3rd party python modules for use with CASA

Postby jmarvil » Fri Dec 09, 2011 4:22 pm

Sure Adam, please feel free to repost this under the casaguides, -Josh
jmarvil
 
Posts: 8
Joined: Sat Nov 19, 2011 10:43 am

Re: Configuring 3rd party python modules for use with CASA

Postby elenc » Tue Mar 13, 2012 3:09 am

Hi Josh,

Great write-up. I was just wondering - how did you overcome the problem of the Casa version of python requiring /usr/bin/gcc-4.2 when trying to build/install python packages? I was attempting to install pyfits into my Casa distribution and came across this issue (I have the Mac OS X gcc compiler and also a more complete ma ports compiler).

Cheers,

Emil.
elenc
 
Posts: 5
Joined: Tue Mar 13, 2012 3:02 am

Re: Configuring 3rd party python modules for use with CASA

Postby elenc » Tue Mar 13, 2012 8:17 pm

Hi All,

I managed to find a quick fix (I'm not sure how appropriate it is but at least I've managed to get pyfits installed). I downloaded gcc-4.2-5566-darwin8-all.tar.gz from http://r.research.att.com/tools/ and installed it in the root directory as suggested by the page. This does not affect existing compilers on the system (I have the original system one and also a more recent one installed as part of MacPorts) and it seems to provide gcc-4.2 and gfortran-4.2 (as needed by the case version of python).

Cheers,

Emil.
elenc
 
Posts: 5
Joined: Tue Mar 13, 2012 3:02 am

Re: Configuring 3rd party python modules for use with CASA

Postby elenc » Wed Mar 14, 2012 10:15 pm

Hi All,

It seems I spoke too soon with regards to solving my particular issue. So pyfits installed OK, but I guess this is because it doesn't depend on any compiled code (i.e. it is a python-based package). I just tried to install pyephem (which depends on a C library that it compiles during installation) and this appears to build but when doing an "import ephem" in the CASA version of python it complains about this library with:

Code: Select all
/Applications/CASA.app/Contents/MacOS/python
Python 2.6.5 (r265:79063, Jun 25 2010, 11:18:26)
[GCC 4.2.1 (Apple Inc. build 5659)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ephem
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Applications/CASA.app/Contents/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ephem/__init__.py", line 5, in <module>
    import ephem._libastro as _libastro
ImportError: dlopen(/Applications/CASA.app/Contents/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ephem/_libastro.so, 2): no suitable image found.  Did find:
   /Applications/CASA.app/Contents/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ephem/_libastro.so: mach-o, but wrong architecture

I'm guessing that this still has to do with differences in the compiler that I'm using.

Does anyone know what compiler is used to build the distributed version of CASA for Mac OS X? Could anyone confirm that they have successfully built and used a package that depends on compiled code (such as pyephem)?

Cheers,

Emil.
elenc
 
Posts: 5
Joined: Tue Mar 13, 2012 3:02 am

Re: Configuring 3rd party python modules for use with CASA

Postby elenc » Wed Mar 14, 2012 11:59 pm

Hi All,

Me again, it appears I installed the wrong compiler for my flavour of Mac OS X (i.e. Lion). What I really needed was gcc-42-5666.3-darwin11.pkg. pyfits still works and I could even install pip and then use it to install pyephem - this makes life a lot easier e.g.

Code: Select all
# Install pip
sudo /Applications/CASA.app/Contents/Frameworks/Python.framework/Versions/2.6/bin/easy_install pip
# Install pyephem
sudo /Applications/CASA.app/Contents/Frameworks/Python.framework/Versions/2.6/bin/pip install pyephem


Cheers,

Emil.
elenc
 
Posts: 5
Joined: Tue Mar 13, 2012 3:02 am

Re: Configuring 3rd party python modules for use with CASA

Postby jacobs » Fri Mar 23, 2012 4:23 pm

Hi All,

We worked through the installation problem last year and came up with a collection of packages that installs our most commonly used packages over CASA. It is available at:
http://loco.lab.asu.edu/~jacobs/Software.html

It currently adds the following modules to CASA:
AIPY
pyephem
mpl_basemap
pyfits
vo.table

Installation is a two step process. 1) Download-unpack 2) run the installer pointing to you your CASA install. It adds a new script "casapython" which you can then use to install your own additional modules. See the web page for details.

Please let me know if it works for you, or you have something better!

Cheers,
~Danny
jacobs
 
Posts: 3
Joined: Thu Oct 06, 2011 5:07 pm

Re: Configuring 3rd party python modules for use with CASA

Postby jmarvil » Wed May 02, 2012 1:03 pm

Thanks for all the information about this issue. As it would happen, I also tried installing pyfits after posting this guide and ran into issues.
It seems that my guide will only work for pure python modules, and will not work for more complex things like pyfits which requires compiling (eg. gcc).
There is a CASA development package which has the required compilers, but it is not shipped with the CASA releases. It may be available upon request from the developers.

Also, there has been some discussion about including additional packages such as pyfits in a future release, but I am not sure if this will be in 3.4.
jmarvil
 
Posts: 8
Joined: Sat Nov 19, 2011 10:43 am

Re: Configuring 3rd party python modules for use with CASA

Postby elenc » Thu May 03, 2012 6:28 am

Hi All,

It would definitely be handy having some of the more fundamental and useful astronomical packages included in casa e.g. pyfits, pyephem and pywcs. These are relatively simple to install and do not add too much excess baggage to the overall casa installation.

Cheers,

Emil.
elenc
 
Posts: 5
Joined: Tue Mar 13, 2012 3:02 am


Return to CASA

Who is online

Users browsing this forum: No registered users and 2 guests

cron