It's not totally clear to me what you mean by load
. That could mean Open
and Close
files in the IDLE editor. Or it could mean being able to use the Python import
statement to load existing Python modules from other files. I'll assume the latter, that by load
you mean import
.
There are two general ways to launch IDLE on Mac OS X. One is from the command line of a terminal session; if you installed Python 3.2 using the python.org installers, by default typing /usr/local/bin/idle3.2
will work. The other way is by launching IDLE.app
from /Applications/Python 3.2
, i.e. by double-clicking its icon. Because you say the default directory for files is your Documents
folder, I'm assuming you are using the second method because IDLE.app
sets Documents
as its current working directory, which becomes the default directory for *Open*s and *Save*s and is automatically added as the first directory on Python's sys.path
, the list of directories that Python
uses to search for modules when import
ing.
If you want to add other directories to sys.path
, as you've noted you can use the PYTHONPATH
environment variable to do so. The standard way to do this is to add an export PYTHONPATH=...
definition to a shell startup script, like .bash_profile
. However, if you use IDLE.app
, no shell is involved so commands in .bash_profile
have no effect.
While there are ways to modify the environment variables for OS X GUI apps, in this case, a simpler solution is to use the other method to invoke IDLE, from the command line of a shell session, using either /usr/local/bin/idle3.2
or, if you've run the Update Shell Profile
command in the /Applications/Python 3.2
folder (and opened a new terminal session), just idle3
. Then, a PYTHONPATH environment variable you set up will be inherited by that IDLE.
BTW, there is no direct way to modify the initial current working directory of IDLE.app
from Documents
other than modifying the code in IDLE. If you start IDLE from a command
line, it inherits the current working directory of the shell.
[UPDATE] But rather than fooling around with defining PYTHONPATH
, here is another even simpler, and probably better, approach that should work with either IDLE.app
or the command line idle
. It takes advantage of Python path configuration (.pth
) files and user site-package directories. Assuming you are using a standard Python framework build of 3.2 (like from a python.org installer) on Mac OS X, create a path file for the directory you want to permanently add to sys.path
. In a terminal session:
mkdir -p ~/Library/Python/3.2/lib/python/site-packages
cd ~/Library/Python/3.2/lib/python/site-packages
cat >my_paths.pth <<EOF
/Users/YOUR_USER_NAME/path/to/your_additional_python_directory_1
/Users/YOUR_USER_NAME/path/to/your_additional_python_directory_2
EOF
Now, whenever you run that Python 3.2 or IDLE under your user name, the directories you have added to the .pth
file will automatically be added to sys.path
.
BTW, the exact path location of the user site-packages directory for versions of Python earlier than 3.2 or 2.7 may be slightly different. Also, on other Unix-y systems, the default location for the user site-package directory is ~/.local/lib/python3.2/site-packages
.