IDLE and Python have a different path on Mac OS X

I am running Mac OS X 10.5.8. I have installed Python 2.6 from the site. It's in my app directory. I edited my .bash_profile to have:

# Setting PATH for MacPython 2.6
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}"
export PATH
export PATH=/usr/local/mysql/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
export PYTHONPATH=/Users/blwatson/pythonpath:/Users/blwatson/pythonpath/django/bin:$PYTHONPATH

      

when i run python from the command line i can get this:

Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 0, 4, 'alpha', 0)

      

PATH check

>>> import sys
>>> sys.path
['', '/Users/blwatson/pythonpath', '/Users/blwatson/pythonpath/django/bin', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/wx-2.8-mac-unicode']
>>> 

      

When I am at IDLE I get a different experience.

Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "copyright", "credits" or "license()" for more information.

    ****************************************************************
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    ****************************************************************

IDLE 2.6.2      
>>> import django

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import django
ImportError: No module named django
>>> import sys
>>> print sys.path
['/Users/blwatson/Documents', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/wx-2.8-mac-unicode']

      

I have no idea what's going on. I switched from one laptop to another and did the whole TimeCapsule, so I know that there is a conflict because of this. Where does IDLE get PATH? Why can't I import Django?

+2


source to share


2 answers


As with all OS X application packages, if you IDLE.app

double-click the shell, the shell will not be involved and therefore, bash_profile

or other shell initialization files will not be called. There is a way to set user session environment variables using a custom property list ( ~/.MacOSX/environment.plist

) file , but this is really a bit of a postponement and not recommended.

Fortunately, there is an easier solution: on OS X, you can also invoke a IDLE

shell from the command line in a terminal window. Thus, it inherits the exported environment variables from that shell, as you would expect. So something like:

$ export PYTHONPATH= ...
$ /usr/local/bin/idle2.6

      

There were various inconsistencies and issues with IDLE on OS X prior to 2.6.2 depending on how it was called, so I recommend using no older versions of python.org 2.6.2 or 3.1 on OS X.



EDIT: open(1)

From the page, you can see that as of 10.4, applications launched through open

will also inherit environment variables, which will also work from the command line. If you want to avoid opening a terminal window, it's easy to create a simple startup application using AppleScript or Automator (or even Python with py2app!). In this case, use the open command to keep the launcher app from sitting. For example, in Automator, select an action Run Shell Script

and add:

export PYTHONPATH= ...
open -a "/Applications/Python 2.6/IDLE.app"

      

Save it as a file format Application

(at 10.5) and you should have an interactive way to launch an individual IDLE.

+2


source


This seems to be a common problem:

http://www.google.com/search?q=python+idle+pythonpath



Unfortunately, there are no answers. The only suggestion seems to have been to edit the executable idle

and add some lines sys.path.insert(...)

.

0


source







All Articles