OtherPackages: Difference between revisions
No edit summary |
No edit summary |
||
Line 83: | Line 83: | ||
along with clear, simple instructions! In short, grab this script, make it executable, and use it (casa-python) in | along with clear, simple instructions! In short, grab this script, make it executable, and use it (casa-python) in | ||
place of python when calling setup.py. | place of python when calling setup.py. | ||
<source lang="bash"> | |||
# In the shell | |||
casa-python setup.py install | |||
</source> | |||
As noted in the docs, this script assumes that CASA is still using Python 2.6. That will need to be upgraded if | As noted in the docs, this script assumes that CASA is still using Python 2.6. That will need to be upgraded if |
Revision as of 17:59, 13 September 2013
CASA ships with a few third party packages (NumPy, SciPy, Matplotlib). It can be very useful to upgrade these or add additional packages. The method to do this can vary from package to package and OS to OS, but many of these packages use the same "distutils" approach and we can summarize a general path.
Disclaimer: This is a writeup documenting the experience at NRAO Charlottesville as of mid-2013. Your mileage may vary, but we hope this orients you and at least gets you started.
The Basic Idea
The process of installing a third party package usually has two steps:
- Building the package using the appropriate version of python for CASA.
- Making sure the package is in a path visible inside CASA so that it can be imported.
The biggest complication is that CASA ships with its own version of python. In order to use a package inside CASA you need to be sure to build that package using this version of python, which may differ from other versions on your system. Another complication, which is usually more minor, is that (depending on permissions) you may need to add the locale of the built package to your path inside CASA.
Calling setup.py
Generally, once you identify the correct python version to use, you will
- Download the buildable version of package in question (usually a ".tar.gz" file).
- Untar and unzip it into a working directory and change directory to that directory.
In that directory you will see a script called "setup.py". You will build the package by calling a variation on
# In the shell
python setup.py install
from the shell.
Generally, an option to install will let you direct where the built package goes. By default it will go to python's "site-package" directory, which is the default home for third party packages. CASA has its own version of this (where it lives exactly depends on your installation), but you may or may not actually have access to this. Try
# In the shell
python setup.py install --help
To see your options. We'll discuss the specific cases of Mac and Linux next.
Your init.py File
Once you have a built version of a package, you need to be sure that CASA can see it. The easiest way to this is to modify your "init.py" file. This is a file that CASA executes every time it starts. It lives in your home directory in a subdirectory called .casa/ so that on a typical system you can see it by
# In the shell
cat ~/.casa/init.py
Now you may not necessarily have an init.py. If you don't, that's no problem you can just create one. If you haven't done so before you just make a text file and include
# python
print "This is my initialization file in ~/.casa/init.py"
Every time CASA starts you should see this line.
Key to installing third party packages, inside this init.py you can add lines like this:
# python
sys.path.append("/users/somebody/somedirectory/")
Then that directory will be in the path that casapy searches when trying to import something. If you don't build to a directory that is automatically in the path, you will need to add a line like this that points to where the built package lives.
On the Macintosh
You are in huge luck. Most astronomers can administrate their own Mac and the location of CASA is standardized from Mac to Mac. This allowed Tom Robitaille to write a simple script that makes installing third party packages extremely simple. The script lives here:
https://github.com/astrofrog/casa-python
along with clear, simple instructions! In short, grab this script, make it executable, and use it (casa-python) in place of python when calling setup.py.
# In the shell
casa-python setup.py install
As noted in the docs, this script assumes that CASA is still using Python 2.6. That will need to be upgraded if and when casapy steps forward in version.
Complications
You knew it wasn't always going to be that easy. Some of these packages, specifically the ultra-important SciPy, require a fortran compiler and Mac OS doesn't (at least at the moment) ship with one. In this case you will need to go grab a fortran compiler and install it on your Mac. One good option here is gfortran and you can find instructions to install it by googling gfortran and Mac.
(We'll try to expand this section with more specific information as time goes along.)
On Linux
Linux - especially Linux on a system administered by someone other than you - is more complicated. You will run into two obstacles:
- paths - paths for CASA are less standard, so you will need to do a little detective work to identify the CASA python.
- permissions - you may not have permission to write to the site-packages directory on a system with a shared installation of CASA. In
this case you will need to install to somewhere else.