0

I have a very basic issue with my Python 3.4 install on MAC OSX 10.11.4. I have set my PYTHONPATH in my .bash_profile and the paths are found when running python from the terminal, and if I import sys and inspect sys.path in the terminal I see my expected paths.

However, when I load IDLE and look at the Path Browser, the PYTHONPATH entries are not in sys.path and my code doesn't run. There are several posts that talk about adding code to add to the sys.path in IDLE, but that's a hack that I don't want to do. How can I get IDLE to read the PYTHONPATH entries into sys.path?

Some further information: On Windows I set up a PYTHONPATH environment varaiable and the paths do show up in the Path Browser as expected.

Is this a basic issue with IDLE on OSX, or perhaps I have something messed up in the install, or ?

Scott Roberts
  • 1,009
  • 8
  • 14
  • 1
    Are you running IDLE from Launchpad? It will not inherit the environment variables set in .bash_profile unless you run it from bash. – cdarke Apr 14 '16 at 19:22
  • Thanks, that answers my question. I was running by clicking the IDLE icon. Running from bash I indeed see the paths. – Scott Roberts Apr 14 '16 at 19:29
  • See also http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x – cdarke Apr 14 '16 at 19:32

1 Answers1

0

The reason for that behavior is that you have different scopes of your environment variables. The variables you've set in .bash_profile will only be loaded if you start a new bash session by opening the terminal. But when you open IDLE by clicking on it you have a different set of environment variables. This is the reason why it works when you call IDLE via terminal. This way all the environment variables get passed to the process you start.

There are at least two solutions:

  1. Always open IDLE from terminal
  2. change the environment variables for all apps which are started via gui. This can be done by editing /etc/launchhd.conf (In Ubuntu you would modify ~/.profile). Look here. But if I remember correctly this doesn't work for opening apps via spotlight.
Picard
  • 983
  • 9
  • 23