IRAF in a virtual Python

Unless and until PyRAF is added to the Python library sets in MacPorts, it is necessary to install it into one's virtual Python environment; installing PyRAF requires an active IRAF to be available; but SciSoft's IRAF is too entangled with SciSoft's Python libraries to be employed separately. Herewith instructions on how to set up the freestanding 64-bit IRAF, which can be installed from Self-Service if necessary, for this purpose.

Please see:

IRAF startup files and aliases

Readers in Astrophysics can add the following aliases to their shell startup files:

  • .cshrc:

    alias iraf-init 'Activate iraf-new'

  • .bashrc:

    alias iraf-init='Activate iraf-new'

Those for whom this is not possible can proceed as follows:

  • Long-form, for use with tcsh:

    Put in $HOME/bin/iraf-init.csh:

    set iraf_prefix=/Local/iraf-2.16.1
    if ( -d "$iraf_prefix" ) then
    echo "64-bit IRAF found"
    echo "*** Sorry: 64-bit IRAF not found" >/dev/tty
    exit 1

    setenv iraf "$iraf_prefix/iraf/"
    setenv IMTOOLRC "$iraf/dev/imtoolrc"
    setenv PATH "$iraf_prefix/irafbin:$PATH"
    source $iraf/unix/hlib/setup.csh

    Then add to your .cshrc:

    alias iraf-init "source $HOME/bin/iraf-init.csh"

  • Long-form, for use with bash:

    Put in $HOME/bin/iraf-init.bash:

    if [ -d "$iraf_prefix" ] ; then
    echo "64-bit IRAF found"
    elif [ -z "$PS1" ] ; then
    echo "*** Sorry: 64-bit IRAF not found --- exiting" 1>&2
    exit 1
    echo "*** Sorry: 64-bit IRAF not found" 1>&2
    return 1

    iraf="$iraf_prefix/iraf/" ; export iraf
    IMTOOLRC="$iraf/dev/imtoolrc" ; export IMTOOLRC
    PATH="$iraf_prefix/irafbin:$PATH" ; export PATH
    . $iraf/unix/hlib/

    Then add to your .bashrc:

    alias iraf-init=". $HOME/bin/iraf-init.bash"

PyRAF initialisation aliases

This assumes that you have set up a virtual Python environment, as described in Virtual Python on Astrophysics Macs, complete with virtual-Python launch aliases vpython3-init or vpython2-init as appropriate.

  • .cshrc:

    alias pyraf3-init "iraf-init && vpython3-init"
    alias pyraf2-init "iraf-init && vpython2-init" (legacy)

  • .bashrc:

    alias pyraf3-init="iraf-init && vpython3-init"
    alias pyraf2-init="iraf-init && vpython2-init" (legacy)

First use:

To take on whichever aliases you've added, you will need to either start a fresh shell session, or say at the shell prompt:

  • tcsh:

    source ~/.cshrc

  • bash:

    . ~/.bashrc

Please note: You only need to do this in shell sessions which are active at the time you add the aliases. Shell startup files are always read and acted upon when the shell starts, but are only read at that point.

Now set up IRAF's, which needs to be in the current directory for IRAF to find it:

  • Activate IRAF if necessary:


  • For each directory in which you're going to use PyRAF, do:

    cd directory-name
    iraf --init +here


.... After all that, you can say either one of:

pyraf2-init (legacy)

.... to initialise the 64-bit IRAF and the appropriate virtual Python environment in one go. This will not, however, actually launch PyRAF:

  • If you have installed PyRAF into your virtual Python, you can now say pyraf at the command line to launch it.

  • If not, please now return to Virtual Python on Astrophysics Macs for directions on how to do so.

Categories: Astro software | Astrophysics | IRAF | PyRAF | virtual Python