0

I am on Mac OS X and I have two Python versions (3.6.11 and 3.8.5) installed via pyenv. The global python version is 3.8.5 and I have a project folder myproject configured with pyenv local to use version 3.6.11 instead. To enable automatic switching between python versions I'm executing eval "$(pyenv init -)" both in my .bashrc and .bash_profile. All this works fine when I use the Mac terminal emulator. python --version gives 3.6.11 when I'm inside myproject and 3.8.5 anywhere else.

However, if I start a jupyterlab server (outside of myproject) and use the terminal emulator from jupyterlab the python version I see is always 3.8.5, even if I'm inside myproject. Even if I manually run eval "$(pyenv init -)" in the jupyterlab terminal the switching still does not work.

EDIT: I have noticed that the $PATH variable I see in the Mac OS terminal is different from the one in the jupyterlab terminal. The former is

/Users/wiebuschm/.local/opt/google-cloud-sdk/bin:/usr/local/Cellar/pyenv-virtualenv/1.1.5/shims:/Users/wiebuschm/.pyenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin

while the latter is

/usr/local/Cellar/pyenv-virtualenv/1.1.5/shims:/Users/wiebuschm/.pyenv/shims:/Users/wiebuschm/.pyenv/versions/3.8.5/bin:/usr/local/Cellar/pyenv/1.2.20/libexec:/Users/wiebuschm/.local/opt/google-cloud-sdk/bin:/usr/local/Cellar/pyenv-virtualenv/1.1.5/shims:/Users/wiebuschm/.pyenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin

However, I don't know what causes this difference and even if I manually set PATH in the jupyterlab terminal to be the same as in the Mac OS terminal it still won't automatically switch the Python version when I cd into myproject.

Martin Wiebusch
  • 1,681
  • 2
  • 11
  • 15
  • Do you have have Jupyter Lab installed for both environments? Could it be that it only runs on 3.8.5 as jupyterlab is not present for 3.6.11? – Robert Young Aug 07 '20 at 10:54
  • I have. Starting jupyter lab outside myproject gives me 3.8.5 and starting it inside gives me 3.6.11 but there is no switching between the two. Just to clarify: I don't care about notebook kernels etc. I'm just using jupyter lab as a terminal emulator and it seems that the pyenv magic isn't working in the jupyterlab terminal. – Martin Wiebusch Aug 07 '20 at 11:24

0 Answers0