1

What is the best way to load in emacs the environment variables of a virtualenv?

I seem to have got virtualenvwrapper.el working. For example, after using venv-workon my_venv, then M-! printenv shows that the environment variable VIRTUAL_ENV has been set to my_venv. Likewise, different virtualenvs load different python versions.

It also seems that I've got the package exec-path-from-shell.el working. For example, in the terminal outside of any virtualenv the command printenv shows MY_ENV_VARIABLE=oy. Now after doing (exec-path-from-shell "MY_ENV_VARIABLE") inside emacs, M-! printenv confirms that MY_ENV_VARIABLE=oy inside emacs as well.

So, I tried doing venv-workon my_venv and then exec-path-from-shell MY_VENV_VARIABLE, which has been set in my_venv. Then, exec-path-from-shell seems to find the value of MY_VENV_VARIABLE to be nil while actually it is voy.

  • 1
    Well... there are too many unknowns... but a relatively easy way to achieve something like this (w/o using third-party packages) would be to parse the output of printenv and use the results with (setenv "variable-name" "variable-value"). – wvxvw Dec 22 '16 at 9:27
  • 1
    See also Reload environment variables – Håkon Hægland Dec 22 '16 at 13:33
  • Ah i see! So the strategy I'd tried is really a nonstarter. But the workaround in that linked answer ...works :). Thank you. – mmw Dec 23 '16 at 2:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.