6

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?

Nick
  • 161
  • Which of the questions here have yo tried and how did they fail - note just look at ones for Mavericks e.g. http://apple.stackexchange.com/questions/106355/setting-the-system-wide-path-environment-variable-in-mavericks?rq=1 or http://apple.stackexchange.com/questions/107787/how-to-set-system-wide-environment-variables-on-os-x-mavericks?rq=1 etc. We want to have one question for this not multiple with different answers – mmmmmm May 08 '14 at 15:40
  • Which GUI application needs to get a variable from the filesystem? – bmike May 08 '14 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 May 08 '14 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 May 08 '14 at 17:05
  • Also for PYTHONPATH a better way is use Python specific setups e.g. vurtualenv – mmmmmm May 10 '14 at 17:13

2 Answers2

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.

thoni56
  • 151
  • 6
1

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

  echo $PYTHONPATH

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
chillin
  • 2,837
  • 2
  • 18
  • 32
  • 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 May 08 '14 at 18:12
  • 1
    @grgarside : Thank you for your suggestion. Please let me know if more explaination is required. Thanks again. – chillin May 08 '14 at 19:53
  • that will do it – Ruskes May 08 '14 at 19:53
  • 4
    How does this set the variable for GUI applications (started via Finder)? – nohillside May 08 '14 at 19:59
  • @patrix : I'm not aware of the distinction in the many ways to set the environment variables for any particular layer of the System. The set of environment variables, as stated by OP, is system-wide. Presumably, if the GUI is using environment variables, it does so in the precise same manner as everything else. We don't have all the answers. We hope to have only at least working solutions. – chillin May 08 '14 at 21:26
  • patrix thx for the suggestion @user77732 see the changes and give this a try – chillin May 10 '14 at 14:28
  • 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 May 10 '14 at 17:14
  • @Mark : if you have any citation for this, or anything that mentions this, that there is something special about the GUI, and environment variables, I'd like to see it. System-wide variable definition should be exactly that... "System-wide." Granted, if it doesn't work, it doesn't work. That's all I got. – chillin May 10 '14 at 23:20
  • @chillin - Apple docs https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man8/path_helper.8.html paths.d just for PATH – mmmmmm May 11 '14 at 11:54