Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pyenv deactivate not working #32

Closed
madgeekfiend opened this issue Jun 29, 2014 · 12 comments · Fixed by #33
Closed

Pyenv deactivate not working #32

madgeekfiend opened this issue Jun 29, 2014 · 12 comments · Fixed by #33

Comments

@madgeekfiend
Copy link

I am using Python 3.4.1 and installed pyenv manually and via homebrew on my Mac OSX running v 10.9.3. After creating a virtualenv and then activating it, which all works. I have a problem with deactivating. When I run 'pyenv deactivate' nothing happens and my shell still shows me as being in the virtualenv.

Any ideas to fix this? Thanks. If I do 'pyenv shell --unset' while in a virtualenv works to 'deactivate'.

Running pyenv deactivate in debug. Hiding my directory name from web scrapers.

++ [pyenv:15] type -p greadlink readlink
++ [pyenv:15] head -1

  • [pyenv:15] READLINK=/usr/bin/readlink
  • [pyenv:16] '[' -z /usr/bin/readlink ']'
  • [pyenv:21] unset GREP_OPTIONS
  • [pyenv:41] '[' -z /Users/HIDDEN/.pyenv ']'
  • [pyenv:44] PYENV_ROOT=/Users/HIDDEN/.pyenv
  • [pyenv:46] export PYENV_ROOT
  • [pyenv:48] '[' -z '' ']'
    ++ [pyenv:49] pwd
  • [pyenv:49] PYENV_DIR=/Users/HIDDEN
  • [pyenv:58] export PYENV_DIR
  • [pyenv:61] shopt -s nullglob
    ++ [pyenv:63] abs_dirname /Users/HIDDEN/.pyenv/bin/pyenv
    +++ [pyenv:28] pwd
    ++ [pyenv:28] local cwd=/Users/HIDDEN
    ++ [pyenv:29] local path=/Users/HIDDEN/.pyenv/bin/pyenv
    ++ [pyenv:31] '[' -n /Users/HIDDEN/.pyenv/bin/pyenv ']'
    ++ [pyenv:32] cd /Users/HIDDEN/.pyenv/bin
    ++ [pyenv:33] local name=pyenv
    +++ [pyenv:34] resolve_link pyenv
    +++ [pyenv:24] /usr/bin/readlink pyenv
    ++ [pyenv:34] path=../libexec/pyenv
    ++ [pyenv:31] '[' -n ../libexec/pyenv ']'
    ++ [pyenv:32] cd ../libexec
    ++ [pyenv:33] local name=pyenv
    +++ [pyenv:34] resolve_link pyenv
    +++ [pyenv:24] /usr/bin/readlink pyenv
    +++ [pyenv:34] true
    ++ [pyenv:34] path=
    ++ [pyenv:31] '[' -n '' ']'
    ++ [pyenv:37] pwd
    ++ [pyenv:38] cd /Users/HIDDEN
  • [pyenv:63] bin_path=/Users/HIDDEN/.pyenv/libexec
  • [pyenv:64] for plugin_bin in '"${PYENV_ROOT}/plugins/"*/bin'
  • [pyenv:65] bin_path=/Users/HIDDEN/.pyenv/libexec:/Users/HIDDEN/.pyenv/plugins/pyenv-virtualenv/bin
  • [pyenv:64] for plugin_bin in '"${PYENV_ROOT}/plugins/"*/bin'
  • [pyenv:65] bin_path=/Users/HIDDEN/.pyenv/libexec:/Users/HIDDEN/.pyenv/plugins/pyenv-virtualenv/bin:/Users/HIDDEN/.pyenv/plugins/python-build/bin
  • [pyenv:67] export PATH=/Users/HIDDEN/.pyenv/libexec:/Users/HIDDEN/.pyenv/plugins/pyenv-virtualenv/bin:/Users/HIDDEN/.pyenv/plugins/python-build/bin:/Users/HIDDEN/.pyenv/versions/test/bin:/Users/HIDDEN/.pyenv/shims:/Users/HIDDEN/.pyenv/bin:/Users/HIDDEN/.rvm/gems/ruby-2.1.2/bin:/Users/HIDDEN/.rvm/gems/ruby-2.1.2@global/bin:/Users/HIDDEN/.rvm/rubies/ruby-2.1.2/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/HIDDEN/.rvm/bin
  • [pyenv:67] PATH=/Users/HIDDEN/.pyenv/libexec:/Users/HIDDEN/.pyenv/plugins/pyenv-virtualenv/bin:/Users/HIDDEN/.pyenv/plugins/python-build/bin:/Users/HIDDEN/.pyenv/versions/test/bin:/Users/HIDDEN/.pyenv/shims:/Users/HIDDEN/.pyenv/bin:/Users/HIDDEN/.rvm/gems/ruby-2.1.2/bin:/Users/HIDDEN/.rvm/gems/ruby-2.1.2@global/bin:/Users/HIDDEN/.rvm/rubies/ruby-2.1.2/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/HIDDEN/.rvm/bin
  • [pyenv:69] hook_path=:/Users/HIDDEN/.pyenv/pyenv.d:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib/pyenv/hooks
  • [pyenv:73] export PYENV_HOOK_PATH=:/Users/HIDDEN/.pyenv/pyenv.d:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib/pyenv/hooks
  • [pyenv:73] PYENV_HOOK_PATH=:/Users/HIDDEN/.pyenv/pyenv.d:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib/pyenv/hooks
  • [pyenv:75] shopt -u nullglob
  • [pyenv:78] command=sh-deactivate
  • [pyenv:79] case "$command" in
    ++ [pyenv:87] command -v pyenv-sh-deactivate
  • [pyenv:87] command_path=/Users/HIDDEN/.pyenv/plugins/pyenv-virtualenv/bin/pyenv-sh-deactivate
  • [pyenv:88] '[' -z /Users/HIDDEN/.pyenv/plugins/pyenv-virtualenv/bin/pyenv-sh-deactivate ']'
  • [pyenv:93] shift 1
  • [pyenv:94] exec /Users/HIDDEN/.pyenv/plugins/pyenv-virtualenv/bin/pyenv-sh-deactivate
    ++ [pyenv-sh-deactivate:12] basename bash
  • [pyenv-sh-deactivate:12] shell=bash
  • [pyenv-sh-deactivate:13] case "$shell" in
  • [pyenv-sh-deactivate:15] echo 'declare -f deactivate 1>/dev/null 2>&1 && deactivate;'
  • [pyenv-sh-deactivate:18] '[' -z 1 ']'
@MortalCatalyst
Copy link

Agree definitely not deactivating on Ubuntu 14.04

@yyuu
Copy link
Collaborator

yyuu commented Jun 30, 2014

If you're having pyenv virtualenv-init - in your shell configuration, it is the expected behaviour as of current impl. The pyenv virtualenv-init will setup the precmd (a hook to be executed before every invocation of commands) and it attempts to activate a virtualenv if it is active in pyenv.

@MortalCatalyst
Copy link

Yes but if you want to deactivate the virtualenv with pyenv deactivate it
should do that.

Currently deactivate isn't turning off.
On 30/06/2014 12:20 pm, "Yamashita, Yuu" notifications@github.com wrote:

If you're having pyenv virtualenv-init - in your shell configuration, it
is the expected behaviour as of current impl. The pyenv virtualenv-init
will setup the precmd (a hook to be executed before every invocation of
commands) and it attempts to activate a virtualenv if it is active in
pyenv.


Reply to this email directly or view it on GitHub
#32 (comment)
.

@yyuu
Copy link
Collaborator

yyuu commented Jun 30, 2014

Ok, I'll try to restore pyenv deactivate even if pyenv virtualenv-init has been enabled.

@yyuu
Copy link
Collaborator

yyuu commented Jun 30, 2014

@madgeekfiend @Flebber I pushed 08b4c94 as a workaround for this issue. Please give it a try and check if the issue has solved.

@fgimian
Copy link
Contributor

fgimian commented Jul 1, 2014

This is related to the original issue I posted here #26

I'm afraid that this new behaviour is causing confusion with my colleagues too. I've been asked on many occasions why deactivate is not working (just was asked now again which is why I came here looking to see if a new issue was logged). 😄

Thank you so much and keep up the great work!
Fotis

@madgeekfiend
Copy link
Author

@yyuu I just checked out the commit you mentioned above and deactivate works on Mac OSX 10.9.3 now. Thanks.

@yyuu yyuu closed this as completed in #33 Jul 1, 2014
yyuu added a commit that referenced this issue Jul 1, 2014
Use `PYENV_DEACTIVATE` to store which virtualenv has been deactivated (fixes #32)
@MortalCatalyst
Copy link

Thank you. Working on Ubuntu 14.04.
On 01/07/2014 1:22 pm, "Yamashita, Yuu" notifications@github.com wrote:

Closed #32 #32 via #33
#33.


Reply to this email directly or view it on GitHub
#32 (comment).

@periodic1236
Copy link

Hi @yyuu, I'm still having some trouble with this. I'm running master (pyenv/pyenv@22f4218 and e2e69b3) and the virtualenv is deactivated correctly but PYENV_VERSION remains set. I thought it would be unset if I'm using activate/deactivate explicitly and not the auto-activation feature.

I am using pyenv virtualenv-init, as shown.

user@ubuntu:~$ pyenv versions
  system
* 2.7.8 (set by /home/user/.pyenv/version)
  3.4.1
  venv341
user@ubuntu:~$ pyenv activate venv341
(venv341) user@ubuntu:~$ pyenv versions
  system
  2.7.8
  3.4.1
* venv341 (set by PYENV_VERSION environment variable)
(venv341) user@ubuntu:~$ env | grep PYENV
PYENV_ROOT=/home/user/.pyenv
PYENV_VERSION=venv341
PYENV_VIRTUALENV_INIT=1
PYENV_SHELL=bash
(venv341) user@ubuntu:~$ pyenv deactivate
user@ubuntu:~$ pyenv versions
  system
  2.7.8
  3.4.1
* venv341 (set by PYENV_VERSION environment variable)
user@ubuntu:~$ env | grep PYENV
PYENV_ROOT=/home/user/.pyenv
PYENV_VERSION=venv341
PYENV_VIRTUALENV_INIT=1
PYENV_SHELL=bash
PYENV_DEACTIVATE=/home/user/.pyenv/versions/venv341

Output of sh-activate and sh-deactivate:

user@ubuntu:~$ pyenv sh-activate venv341
pyenv shell "venv341";
unset PYENV_DEACTIVATE;
source "/home/user/.pyenv/versions/venv341/bin/activate";

(venv341) user@ubuntu:~$ pyenv sh-deactivate
if declare -f deactivate 1>/dev/null 2>&1; then
  export PYENV_DEACTIVATE="$VIRTUAL_ENV";
  deactivate;
fi;

@yyuu
Copy link
Collaborator

yyuu commented Jul 3, 2014

@periodic1236

The pyenv-sh-activate/pyenv-sh-deactivate will try to set/unset PYENV_VERSION only if the auto-activation has been disabled.

If you just want to do every activation/deactivation manually, I would recommend you to just remove eval "$(pyenv virtualenv-init -)" from your shell configuration; it just disables the auto-activation feature.

@periodic1236
Copy link

@yyuu Ah, I think I understand now. Thanks a lot!

@sbhakat
Copy link

sbhakat commented Nov 15, 2018

Seems quite similar issue however I have the following problem while deactivating pyenv

#Checking the version

pyenv versions
  system
  3.6.7
  3.6.7/envs/keras-test
* keras-test (set by /home/sbhakat/.python-version)

Then I progressed as mentioned above

env | grep PYENV
PYENV_ROOT=/home/sbhakat/.pyenv
PYENV_VIRTUALENV_INIT=1
PYENV_VIRTUAL_ENV=/home/sbhakat/.pyenv/versions/3.6.7/envs/keras-test
PYENV_SHELL=bash

Trying to deactivate like

pyenv sh-deactivate keras-test
unset PYENV_VIRTUAL_ENV;
unset VIRTUAL_ENV;
if [ -n "${_OLD_VIRTUAL_PATH}" ]; then
  export PATH="${_OLD_VIRTUAL_PATH}";
  unset _OLD_VIRTUAL_PATH;
fi;
if [ -n "${_OLD_VIRTUAL_PYTHONHOME}" ]; then
  export PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME}";
  unset _OLD_VIRTUAL_PYTHONHOME;
fi;
if [ -n "${_OLD_VIRTUAL_PS1}" ]; then
  export PS1="${_OLD_VIRTUAL_PS1}";
  unset _OLD_VIRTUAL_PS1;
fi;
if declare -f deactivate 1>/dev/null 2>&1; then
  unset -f deactivate;
fi;

I also hashed the following part in .bashrc however seems like it is not working any help?

#if command -v pyenv 1>/dev/null 2>&1; then
#   eval "$(pyenv init -)"
#fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants