Teething troubles with Python on a Mac

T

Thomas Philips

I've got a new iMac, have installed Python 2.5.2 on it, and am now
trying to run my existing Python programs on it (these are typically
number crunching programs that I run from IDLE). Some things work,
while others don't, and as this is my first time grappling with Unix
and MacOS X, I appreciate some guidance on how to get up and running.
Here are details of my setup interspersed with my woes and my
questions. Your assistance is greatly appreciated.

Item 1. I downloaded and installed 2.5.2 from python.org. Runs fine,
it installed a MacPython directory under applications, which has a few
icons, including IDLE. However, I have absolutely NO idea where all
the Python files are kept.

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.

Question 2: In Finder, If I click on Search For > Past week, I can see
a sequence of folders under the horizontal scroll bar at the bottom of
the window, allowing me to determine that some files that were placed
under Applications > MacPython 2.5> Extra> Demo. 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?


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.

Question 3. What do I have to do in order to make SciPy work with both
Python 2.5.1 (that comes with the Mac) and 2.5.2 (that I installed
myself)?


Item 3. I accidentally clicked on something (not sure what) and
suddenly found the path to the numpy folder was Macintosh HD >
Developer > SDKs > MacOSX10.5.sdk>System>
Library>Frameworks>Python.framework>Versions>2.5>extras>lib>Python>numpy.
This is insane!!! Where would the superpack have installed SciPy, and
how can I find it?

Question 4. How do I get MacPython 2.5.2 to see SciPy, NumPy etc.
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.
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?


Item 4. I opened a terminal window, and typed ipython. Here's what I
got:

Welcome to IPython. I will try to create a personal configuration
directory
where you can customize many aspects of IPython's functionality in:

/Users/tom/.ipython
WARNING:
Installation error. IPython's directory was not found.

Check the following:

The ipython/IPython directory should be in a directory belonging to
your
PYTHONPATH environment variable (that is, it should be in a directory
belonging to sys.path). You can copy it explicitly there or just link
to it.

IPython will create a minimal default configuration for you.
Ipython actually runs once I hit enter, but I do not seem to be able
to import and run my programs.

Question 7. What is this cryptic message all about? I'm completely
confused.


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.

Thank you in advance for your help.

Sincerely

Thomas Philips
 
G

greg

Thomas said:
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.
 
A

Avi

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.

On that: how would I go about updating the system Python, then? Or is
that going to be stuck at whatever it is, and Mac users are expected
to run two simultaneous Python installations? I'm not entirely
comfortable with having a separate MacPython (I used to do so, but it
caused so many issues with installing new packages that I gave up on
it) and would prefer to just update system Python.

- Avi
 
T

Timothy Grant

On that: how would I go about updating the system Python, then? Or is
that going to be stuck at whatever it is, and Mac users are expected
to run two simultaneous Python installations? I'm not entirely
comfortable with having a separate MacPython (I used to do so, but it
caused so many issues with installing new packages that I gave up on
it) and would prefer to just update system Python.

- Avi

You will likely cause more problems updating the system python than
managing the two separate installations. OSX relies on the version of
python they ship. While there are likely cases where it could be
replaced completely safely the risks of having to re-install your OS
at some point because it has the wrong version of python are not worth
it.
 
A

Avinash Vora

You will likely cause more problems updating the system python than
managing the two separate installations.

That's sadly worrying.
OSX relies on the version of python they ship.

I think that helps my point--there *are* bug fixes between major
versions despite the new language changes, and that can really only be
a good thing.
While there are likely cases where it could be
replaced completely safely the risks of having to re-install your OS
at some point because it has the wrong version of python are not worth
it.


I haven't been a Mac user long enough to see a major version change (I
was on Linux/XP/Vista for most of 2.4 and switched distributions right
after 2.5 came out, and then XP before that), so I've never seen a
version change, but is this the sort of thing that will be upgraded in
Software Update?

- Avinash
 
T

Timothy Grant

That's sadly worrying.


I think that helps my point--there *are* bug fixes between major versions
despite the new language changes, and that can really only be a good thing.



I haven't been a Mac user long enough to see a major version change (I was
on Linux/XP/Vista for most of 2.4 and switched distributions right after 2.5
came out, and then XP before that), so I've never seen a version change, but
is this the sort of thing that will be upgraded in Software Update?

- Avinash

I haven't paid enough attention to the system python in my four years
as an Apple user to know. I simply installed the python I wanted and
went from there.

I honestly don't think it is a cause for concern though. The situation
is very similar to on Linux (Red Hat has their version of python) you
simply install what you want and use it.
 
G

greg

Avi said:
On that: how would I go about updating the system Python, then?

The usual advice is not to try to do that at all.
Generally it's best to treat anything in /System
as off-limits.
(I used to do so, but it
caused so many issues with installing new packages that I gave up on
it)

I've very rarely had any problem with maintaining my
own Python installation, but as I said, I always install
packages using "python setup.py".

Python itself copes very well with having multiple
versions installed, on all platforms, but you have to
do things the Python way.
 
S

Sean DiZazzo

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.

find / -name "site-packages"

Will lead you to where SciPy and Numpy should be installed for each
Python installation. You can work backwards from there.
Question 2: In Finder, If I click on Search For > Past week, I can see
a sequence of folders under the horizontal scroll bar at the bottom of
the window, allowing me to determine that some files that were placed
under Applications > MacPython 2.5> Extra> Demo. 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 do what you want in Leopard, but not in Tiger. I Don't have a
Leopard install in front of me. Check Finder->Preferences, or Finder-
View->Show View Options
Question 4. How do I get MacPython 2.5.2 to see SciPy, NumPy etc.

I've had very good luck with "easy_install" It downloads and installs
the right package for your install.

http://peak.telecommunity.com/DevCenter/EasyInstall
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.

I'm not even sure it's set. I have never had to worry about it.
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?

It doesn't exist by default, you have to create it. I don't have the
format of the environment.plist in front of me, but if I remember
correctly, you can create it with any text editor. Or you can
download a freeware program to do the whole shebang for you:
http://www.versiontracker.com/dyn/moreinfo/macosx/15073
Item 4. I opened a terminal window, and typed ipython. Here's what I
got:

The ipython/IPython directory should be in a directory belonging to
your
PYTHONPATH environment variable (that is, it should be in a directory
belonging to sys.path). You can copy it explicitly there or just link
to it.

Question 7. What is this cryptic message all about? I'm completely
confused.

Try copying the ipython directory into the corresponding "site-
packages" directory from earlier. Otherwise, scrap it and use
easy_install.

Good luck!

~Sean
 
A

Avinash Vora

(Greg: You only sent the email to me: you probably wanted to add the
mailing list to the recipients.)

The usual advice is not to try to do that at all.
Generally it's best to treat anything in /System
as off-limits.

Right, but I meant if there is an Apple-sanctioned way. I guess not?
I've very rarely had any problem with maintaining my
own Python installation, but as I said, I always install
packages using "python setup.py".

I guess I'll give it a shot, then. Alias in bash to MacPython, I
assume?
Python itself copes very well with having multiple
versions installed, on all platforms, but you have to
do things the Python way.

My point was that it seems to be a bit of a hack.

Thanks for the advice from everyone, though.
 
G

Greg Ewing

Avinash said:
(Greg: You only sent the email to me: you probably wanted to add the
mailing list to the recipients.)

I replied to the newsgroup as well, so it should
turn up in the list.
Right, but I meant if there is an Apple-sanctioned way. I guess not?

Not that I'm aware of.
I guess I'll give it a shot, then. Alias in bash to MacPython, I assume?

You'll probably find that the MacPython installer has set
things up so that simply running "python" in the shell
will get the version it has installed. Check the version
number displayed in the banner when you run it.

If it's not the right one, you could make a symlink
from /usr/bin/python to the one you want (by default it's
symlinked to the system python).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top