Can't find user module despite setting PYTHONPATH

Paul Berkowitz berkowit at silcom.com
Fri Nov 29 18:17:28 EST 2002


On 11/29/02 1:28 PM, in article BA0D1BFD.274AD%berkowit at silcom.com, I wrote:

> Is there anyone here with Mac OS 10.2? Do you know how to get Python to
> recognize PYTHONPATH, as the shell does. Or else what is the right way to
> modify sys.path to it is retained between sessions?

I got a reply off-list, which directed me to the python-mac sig,
http://www.python.org/sigs/pythonmac-sig/.


Although most of the accumulated archives deal with MacPython in the old Mac
OS (the new Mac OS X is BSD Unix, but with its own peculiarities), I did
soon come upon a recent post with a reference to Russell Owen's website,
which sure enough had the answer on one of its pages:

<http://www.astro.washington.edu/owen/AquaEnvVar.html>

It would be good to get that page reference into the python.org FAQ: it's
going to come up frequently since Python is now built into Mac OS 10.2 and
later, but PYTHONPATH is ignored by the Python installation. It is indeed a
Mac OS X-specific issue. Russell's method works.

Here's the full content of Russell's page:

-------------------------------------------------------------

How to define environment variables so that MacOS X applications can see
them.

MacOS X native applications do not see unix environment variables defined in
~/.cshrc or any other of the standard unix configuration files. Normally
this doesn't matter, but certain MacOS X applications can make good use of
environment variables. These include the framework build of Python (which is
used to write wxPython or aqua Tk appliations) and BBEdit (which can
directly run unix scripts, but without your environment variables unless you
define them in this fashion).

The trick is to define your environment variables in the file
~/.MacOSX/environment.plist. The odds are that you'll have to create both
the directory and the file. The format is as per this example:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>DISPLAY</key>
    <string>:0.0</string>
    <key>PYTHONPATH</key>
    
<string>/full/path/ofyour/favorite/script/dir:/full/path/of/another/script/d
ir:</string>
</dict>
</plist>


Notes: 

*    Use absolute paths and spell them out. The home directory shortcut ~
will not be expanded.
*    Whenever you modify the file, log out and then log back in again to use
it (though there might be an easier way to reload it).
*    It may be necessary for the file to have unix line endings. I haven't
tried anything else.
*    I imagine other things can be in the file (such as comments), but I
don't know what. The developer's documentation probably describes the file
in full detail somewhere; I've not looked.


Thanks to the tech support people at BBEdit for first telling me about this
file.


First published 2002-11-08 by
Russell Owen

-- 
Paul Berkowitz




More information about the Python-list mailing list