I am trying to set an environment variable that will be accessible from both a GUI application (Pycharm) as well as from the Terminal. This variable is called PYTHONPATH.

I have tried

Can anyone give me a step by step guide of how to do this correctly on Mavericks?

  • Which of the questions here have yo tried and how did they fail - note just look at ones for Mavericks e.g. apple.stackexchange.com/questions/106355/… or apple.stackexchange.com/questions/107787/… etc. We want to have one question for this not multiple with different answers
    – mmmmmm
    Commented May 8, 2014 at 15:40
  • Which GUI application needs to get a variable from the filesystem?
    – bmike
    Commented May 8, 2014 at 15:40
  • The first link specific details how to set the PATH variable, a very specific environment variable, but unfortunately very different from a generic environment variable like PYTHONPATH. The second like is more helpful. He says that launched.conf is still supported. This is good news and is one of the files that I tried setting previously. Perhaps my syntax is wrong. Can anyone verify it? Here is what my file looks like: setenv PYTHONPATH ~/Documents/CrowdSurfer
    – Nick
    Commented May 8, 2014 at 16:03
  • Until your accounts get merged, just edit the post to explain how the linked answers don't make sense or solve your specific issue. No need to tack on edit: at the end of the post - just make the words flow with the new data included as best fits.
    – bmike
    Commented May 8, 2014 at 17:05
  • Also for PYTHONPATH a better way is use Python specific setups e.g. vurtualenv
    – mmmmmm
    Commented May 10, 2014 at 17:13

2 Answers 2


At this point in time (2022, Montrey) most hacks are not working. But the good news is that you can use launchctl in your shell, either explicitly (and until reboot)

launchctl setenv LANG "sv_SE"
launchctl setenv PATH `echo $PATH`

or in a script in your .bashrc.

There are of course a couple of ways to make such a command run a startup too.

NOTE: of course you cannot change environment variables for already running apps.


Check your current PYTHONPATH setting by opening /Applications/Utilities/Terminal.app and typing the following command and hit the return key:


Try this alternate syntax in Terminal.app to see if it sets your PYTHONPATH correctly. Recheck the result with the above command again. If so, put the line in your ~/.bash_profile (although a file in /etc/paths.d/ with just the PATH, no commands, ought to set this system-wide).

  export PYTHONPATH=$PYTHONPATH\ : $USER/Documents/CrowdSurfer ; export PYTHONPATH
  • Could you expand on what each part of this does? A block of code like this isn't really self-explanatory to most users
    – grg
    Commented May 8, 2014 at 18:12
  • 1
    @grgarside : Thank you for your suggestion. Please let me know if more explaination is required. Thanks again.
    – chillin
    Commented May 8, 2014 at 19:53
  • that will do it
    – Ruskes
    Commented May 8, 2014 at 19:53
  • 4
    How does this set the variable for GUI applications (started via Finder)?
    – nohillside
    Commented May 8, 2014 at 19:59
  • 2
    @chillin - This is the issue in OSX environment variables cannot be set for GUIS and command line in the same way. In command line it is a simple edit of profile files GUI has to be done another way
    – mmmmmm
    Commented May 10, 2014 at 17:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .