pyenv-virtualenv icon indicating copy to clipboard operation
pyenv-virtualenv copied to clipboard

Pyenv activate does not source activate script

Open ianbrayoni opened this issue 6 years ago • 2 comments

Shouldn't pyenv activate work the same way as source /Users/me/.pyenv/versions/3.6.8/envs/app-x-py3.6.8/bin/activate?

Create virtualenv

➜  app-x git:(master) % pyenv virtualenv 3.6.8 app-x-py3.6.8
Looking in links: /var/folders/0s/d48cqfy96vl2gqmy_gjvcknm0000gn/T/tmpfxy7zwlo
Requirement already satisfied: setuptools in /Users/me/.pyenv/versions/3.6.8/envs/app-x-py3.6.8/lib/python3.6/site-packages (40.6.2)
Requirement already satisfied: pip in /Users/me/.pyenv/versions/3.6.8/envs/app-x-py3.6.8/lib/python3.6/site-packages (18.1)

Activate

Expected

➜  app-x git:(master) % pyenv activate  app-x-py3.6.8
(app-x-py3.6.8) ➜  app-x git:(master) %
(app-x-py3.6.8) ➜  app-x-py3.6.8 git:(master) % source /Users/me/.pyenv/versions/3.6.8/envs/app-x-py3.6.8/bin/activate
(app-x-py3.6.8) pyenv-virtualenv: version `app-x-py3.6.8' is already activated
(app-x-py3.6.8) ➜  app-x-py3.6.8 git:(master) % pyenv deactivate
➜  app-x git:(master) %
➜  app-x git:(master) % pyenv deactivate
pyenv-virtualenv: no virtualenv has been activated.

Actual

The prompt (app-x-py3.6.8) does not show

➜  app-x git:(master) % pyenv activate app-x-py3.6.8
➜  app-x git:(master) % pyenv activate app-x-py3.6.8
pyenv-virtualenv: version `app-x-py3.6.8' is already activated
➜  app-x git:(master) % pyenv deactivate
➜  app-x git:(master) %
➜  app-x git:(master) % pyenv deactivate
pyenv-virtualenv: no virtualenv has been activated.

Source works after pyenv activate app-x-py3.6.8 instead of displaying

pyenv-virtualenv: version `app-x-py3.6.8' is already activated

➜  app-x git:(master) % pyenv activate app-x-py3.6.8
➜  app-x git:(master) % source /Users/me/.pyenv/versions/3.6.8/envs/app-x-py3.6.8/bin/activate
(app-x-py3.6.8) ➜  app-x git:(master) %
(app-x-py3.6.8) ➜  app-x git:(master) % pyenv deactivate
➜  app-x git:(master) %
➜  app-x git:(master) % pyenv deactivate
pyenv-virtualenv: no virtualenv has been activated.

Notes

I am on:

  • MacOS Mojave version 10.14.6
  • pyenv 1.2.13
  • I use zsh, I have the following in my ~/.zshrc:
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

ianbrayoni avatar Sep 25 '19 17:09 ianbrayoni

This is puzzling to me, too. When I inject a simple line like

echo "Hello, from pyenv activate..." > ~/hello.txt

there appears to be no effect. However, if I remove the corresponding bin/activate which I modified, I get the following error:

pyenv-virtualenv: version `my_custom_activation_test' is not a virtualenv

So it appears that pyenv activate my_custom_activation_test checks for the existence of ~/.pyenv/versions/my_custom_activation_test/bin/activate, as part of the environment validation but then does not execute its contents.

I am on:

  • MacOS 11.5.1 (20G80)
  • pyenv 2.0.3

byronformwalt avatar Aug 08 '21 04:08 byronformwalt

I have the same issue on Ubuntu Linux 20.04, brand new install of pyenv.

mprat avatar Sep 19 '21 13:09 mprat