MacPorts on Apple Macintosh Systems

The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading a wide range of Free and Open-Source Software on the OS X operating system. The Department of Physics has a large number of MacPorts software installed on the Apple Macintosh systems, which should be available from the command line or from the /Applications/MacPorts directory.

The software is compiled centrally on a twice-weekly basis, and distributed regularly to all desktop systems. You can also build your own MacPorts software with MyMacPorts. If software isn't already installed on the Apple Macintosh systems and you cannot install it via MyMacPorts then please email:

itsupport@physics.ox.ac.uk

Please see also:

How do I find out what is installed?

I'll use EMACS and the GNU Software Library as examples.

  • Package names:

    port search emacs gsl

    .... will show all packages whose names include the strings "emacs" or "gsl", whether installed or not.

  • Information about packages:

    port info xemacs gsl

  • Is this package installed by its exact name ....

    port installed xemacs gsl

  • .... or by partial name?

    port installed | grep emacs

Simply looking for a library in /opt/local/lib may yield strange results. For example, at the time of writing, a customised version of libcpgplot.dylib is installed in MacPorts apparently only as a dependency of Miriad, and the corresponding header file isn't where it ought to be.

Please Note (Astrophysics system only): This is now folded into "Activate search": please see Help and Search in Applications Setup.

How do I link to libraries installed by MacPorts?

If you wish to link one or more of the MacPorts libraries into your own software, add the following command-line option to your compiler, to tell it where the libraries live:

-L/opt/local/lib

(no space after the capital L). To find C header files, use also:

-I /opt/local/include

(including the space after the capital I). These will work both in shellfiles and at the command line. In Makefiles, you may wish to use something of the following form:

MACPORTS := /opt/local
CFLAGS   += -I $(MACPORTS)/include
LDFLAGS  += -L$(MACPORTS)/lib

.... which makes use of GNU make's simple-assignment and append-to operators to (try to) avoid death by infinite recursion, while building up $(LDFLAGS) and $(CFLAGS) by parts. (The well-tempered Makefile will already have a line of the form

LDLIBS = -lfoo -lbar -lbaz

to tell the link phase of the compilation process to pick up libfoo, libbar and libbaz, in that order, for appropriate values of foo, bar and baz.)

MacPorts Python libraries

If you say python2 at the command prompt (instead of python), you will then be using the copy of Python 2.7 in MacPorts, and the matching library set; this is rather more up-to-date and better fleshed-out than the system's Python libraries, or the frankly obsolete SciSoft or Astropack sets. Similarly, say ipython2 instead of ipython, or jupyter-2.7 rather than jupyter. Better yet (see below), get ahead of the crowd and start using python3 (resp, ipython3, jupyter-3.5) instead.

PLEASE NOTE:

  • Using MacPorts's Python may or may not preempt Python libraries which have been installed elsewhere (eg under one's home directory) as "eggs". These have an insidious habit of hoisting themselves up Python's sys.path, which makes them difficult to preempt by more normal Python library installations.

  • The previous advice to say Activate python-macports at the shell prompt has been superceded, and is hereby revoked. The consequences of mixing library sets from different Python instances is at best undefined, and is likely to work at best on a "fails to fail" basis.

  • Use of the Python libraries present in SciSoft (and the AstroPack) is hereby deprecated. Both are badly out-of-date, and the results of playing mix-and-match with them and MacPorts's libraries are at best undefined.

  • Python 2.7 is not long for this world. You should instead be using Python 3 (3.5 or 3.6 at the time of writing), by saying python3, or ipython3 or jupyter-3.5 (as appropriate), at the command line.

    • Most of the important packages have been ported to Python 3. If you find any which haven't been, and which are important to you, please let us know at the usual e-mail address.

    • Please see the article on virtual Python for how to amend freestanding Python scripts which use the "flash-bang" mechanism to find the appropriate Python executables.

For further information please see:

MacPorts on Laptops

Please note: This does not apply to our desktop systems, whatever (erm) well-meaning advice you may read elsewhere.

All MacBooks will have Physics MacPorts installed on them when they are set up by IT Support. From that point on, you will be responsible for updating the MacPorts installation, using (at the shell prompt):

sudo port selfupdate
sudo port upgrade outdated

.... in the standard documented MacPorts fashion.

If you wish to update to the latest build of Physics's MacPorts installation, you can do this with the Self Service application.

PLEASE NOTE: Using Self-Service to do the update will remove any local changes to MacPorts, notably any ports which you may have installed for yourself. The careful Physicist will therefore first save the list of installed packages (eg by saying port installed requested | tee ~/port-list.out at the shell prompt beforehand), then check afterwards what's missing.

Categories: Apple | Astro software | Astrophysics | Development | Mac | OS X | macports | python