Teething troubles with Python on a Mac

greg greg at cosc.canterbury.ac.nz
Sun Aug 3 01:49:37 EDT 2008


Thomas Philips wrote:

> Question 1: How can I locate the Python installation? There a few
> files under Applications > MacPython 2.5, but this is clearly not the
> entire installation.

Have a look in

   /Library/Frameworks/Python.framework/Versions/2.5

 > But I do not seem to
> be able to see the sequence of folders under the horizontal scroll bar
> in any finder window. What do I need to do to make the folder sequence
> visible in all Finder Windows?

You can't -- this feature only exists in the Search window,
which is a different kind of window from the normal Finder
windows.

However, in a normal Finder window, if you click and hold
with the Command key on the title displayed in the title
bar at the top of the window, you'll get a pop-up menu
showing the position of the folder you're looking at in the
nesting hierarchy.

> Item 2. I downloaded and installed the SciPy superpack from
> Macinscience,org. Scipy seems to import correctly into the Python
> 2.5.1 that comes with the Mac, but i cannot import it into MacPython
> 2.5.2.

I'm not familiar with SciPy distributions, but if it's some
sort of double-clickable installer, it's likely that it's only
designed to install into the system Python (i.e. the one that
comes installed with MacOSX).

See if it has installed anything into

   /Library/Python/2.5/site-packages

If so, you could try moving or copying them into

   /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages

> Question 5. How can I find the current value of the PYTHONPATH
> environment variable, and how can I edit it and add a directory in
> which I keep my Python programs.

To find out its current value, in a Terminal window,

   echo $PYTHONPATH

To have it set each time you open a Terminal window,
one way is to put something like this in your ~/.bashrc
file:

   PYTHONPATH=whatever_you_want
   export PYTHONPATH

However, because the filename starts with a dot, it
won't show up in the Finder or any Save dialog boxes,
making it a bit tricky to edit with a GUI-based text
editor. There's some advice here on how to deal with
that:

   http://discussions.apple.com/thread.jspa?threadID=1007602

> Question 6. Apparently there's a Property List Editor that must be
> used to create a file called ~ /.MacOSX/environment.plist. I can't
> find a directory called ~/.MacOSX. Is this a hidden directory?

I've never tried that method myself, but it sounds
plausible. You'll have similar difficulties with the
name .MacOSX not showing up in the Finder. However,
you can get to it using the "Go To Folder..." command
under the "Go" menu in the Finder and typing in the
full pathname.

If there isn't already an environment.plist file
there, you may have to save it somewhere else first
and then drag it into the .MacOSX folder.

The Property List Editor comes with the Developer
Tools and lives in /Developer/Applications/Utilities.

> Item 4. I opened a terminal window, and typed ipython. Here's what I
> got:
> 
> /Users/tom/.ipython
> WARNING:
> Installation error. IPython's directory was not found.

It's quite likely that this will correct itself once you
get the relevant files into the right site-packages folder.

Also, if this is your only reason for wanting to set
PYTHONPATH, you may not have to worry about that either.

> I never thought I'd say this, but it actually seemed a lot easier to
> get Python and any associated programs up and running on Windows! I
> suspect that a large fraction of my troubles are due to the fact that
> I am brand new to the Mac and to Unix, but I bought the Mac in part
> because I thought that using it was effortless.

It's generally pretty smooth (although different from Windows
in many ways, so you do need to learn some new things) as
long as you stick to GUI-style applications. Python doesn't
quite fit into that way of working, however. You need to
know a bit about what's going on underneath, particularly
when managing your own Python installation.

The way I approach Python on MacOSX is to treat it as a
Unix system and use the standard Python method of installing
packages, i.e. use Python to run a setup.py file. This
ensures that the package will be installed into whichever
Python is being used to run the setup.py.

Apart from the initial installation of Python itself, I
never use an installer to install a Python package if I
can avoid it. I wouldn't trust it to install into the right
Python version.

-- 
Greg



More information about the Python-list mailing list