purcell / exec-path-from-shell

Make Emacs use the $PATH set up by the user's shell
Other
1.43k stars 82 forks source link

Copying a virtualenv's PYTHONPATH #24

Closed nayefc closed 8 years ago

nayefc commented 9 years ago

Hello,

I have a $PYTHONPATH being set when a Python virtualenv is being activated. When I activate the virtualenv in Emacs using pyenv-mode, I am calling exec-path-from-shell-copy-env to copy the variable, but it isn't getting copied. Is there anything else that I will need to do, to get it to work with virtualenvs? Has anyone had any success using this package with virtualenvs?

purcell commented 9 years ago

I think you've perhaps misunderstood what this package does.

exec-path-from-shell-copy-env fires up a fresh shell, and asks it to print out the desired env vars. Inside that fresh shell, any virtualenv settings you made inside Emacs will not be visible, and so the $PYTHONPATH in Emacs will not change.

I'm not sure why pyenv-mode alone would be insufficient. Perhaps @proofit404 can comment?

nayefc commented 9 years ago

pyenv-mode does not copy environment variables for some reason.

I have a hacky solution, which is to edit pyenv-mode.el and add call setenv whenever a new virtualenv is being activated. I thought exec-path-from-shell would be able to fix this in a less hacky way.

purcell commented 9 years ago

Don't forget that environment variables are Emacs-wide, so changes will affect every buffer. I presume that pyenv-mode is designed such that it is not necessary to modify them.

nayefc commented 9 years ago

Yeah I think that's fine for me as I rarely have multiple buffers that span multiple Python projects. I don't think pyenv-mode takes PYTHONPATH into account, which is used pretty often for packaging related needs (python packaging is terrible).

proofit404 commented 9 years ago

First of all pyenv-mode deal with pyenv project alone not with pyenv-virtualenv plugin. So processing activation scripts is out of the package goal. I can add customizable hooks running after set or unset python versions. You'll be able to try to get PYTHONPATH with in this hook. But you need to activate you virtual environment in the shell running by exec-path-from-shell-copy-env.