pyenv / pyenv-virtualenv

a pyenv plugin to manage virtualenv (a.k.a. python-virtualenv)
MIT License
6.18k stars 399 forks source link

`pyenv deactivate` has no effect if the environment is the selected version #439

Closed Sukanya-rs closed 1 year ago

Sukanya-rs commented 1 year ago

Pyenv is not deactivating from virtual environment: Python 3.10.6

Description

(pysyft_0.7.0) mac@user1-MacBook-Pro Infrastructure_as_code % 
pyenv deactivate
(pysyft_0.7.0) mac@ user1-MacBook-Pro Infrastructure_as_code % 
(pysyft_0.7.0) mac@ user1-MacBook-Pro Infrastructure_as_code % 

Looked into similar issues before raising current issue. Hope to get some help!

Sukanya-rs commented 1 year ago

Tried the same in 3.8.10 version , it works fine!


mac@macs-MacBook-Pro Project % pyenv virtualenv 3.8.10 test_3
.8.10
Looking in links: /var/folders/k8/vqd8k8s96dbcg8cnv5b9gjt80000gn/T/tmp20jkbec6
Requirement already satisfied: setuptools in /Users/mac/.pyenv/versions/3.8.10/envs/test_3.8.10/lib/python3.8/site-packages (56.0.0)
Requirement already satisfied: pip in /Users/mac/.pyenv/versions/3.8.10/envs/test_3.8.10/lib/python3.8/site-packages (21.1.1)
mac@macs-MacBook-Pro Project % pyenv versions 
mac@macs-MacBook-Pro Project % pyenv versions 
  system
  3.8.10
  3.8.10/envs/test_3.8.10
  3.10.5
* 3.10.6 (set by PYENV_VERSION environment variable)
  3.10.6/envs/pysyft_0.6.0
  3.10.6/envs/pysyft_0.7.0
  pysyft_0.6.0
  pysyft_0.7.0
  test_3.8.10
mac@macs-MacBook-Pro Project % pyenv activate test_3.8.10 
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
(test_3.8.10) mac@macs-MacBook-Pro Project % pyenv deactivate
mac@macs-MacBook-Pro Project %```
Sukanya-rs commented 1 year ago

Tried "source deactivate" command and it worked and closing the issue.

Sukanya-rs commented 1 year ago

I observed the same issue on 3.10 version of python, even "source deactivate" command did not work.

native-api commented 1 year ago

Please provide a debug trace of the faulty invocation for us to be able to say anything.

export PYENV_DEBUG=1
export PS4='+(${BASH_SOURCE:-}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -x
<reproduce the problem>
set +x
unset PYENV_DEBUG
native-api commented 1 year ago

If your shell is Zsh, replace ${BASH_SOURCE:-} with ${BASH_SOURCE:-${(%):-%x}}.

albdv commented 1 year ago

have the same issue on mac m1 when pyenv-virtualenv not deactivating when virtualenv set to global with pyenv

anatoly.lebedev@anatolylebedevs-MacBook-Pro bin % env | grep VIRT
PYENV_VIRTUALENV_INIT=1
PIP_REQUIRE_VIRTUALENV=true
PYENV_VIRTUALENV_DISABLE_PROMPT=1
PYENV_VIRTUAL_ENV=/Users/anatoly.lebedev/.pyenv/versions/3.11.0/envs/tools
VIRTUAL_ENV=/Users/anatoly.lebedev/.pyenv/versions/3.11.0/envs/tools
anatoly.lebedev@anatolylebedevs-MacBook-Pro bin % pyenv deactivate tools
anatoly.lebedev@anatolylebedevs-MacBook-Pro bin % env | grep VIRT
PYENV_VIRTUALENV_INIT=1
PIP_REQUIRE_VIRTUALENV=true
PYENV_VIRTUALENV_DISABLE_PROMPT=1
PYENV_VIRTUAL_ENV=/Users/anatoly.lebedev/.pyenv/versions/3.11.0/envs/tools
VIRTUAL_ENV=/Users/anatoly.lebedev/.pyenv/versions/3.11.0/envs/tools
anatoly.lebedev@anatolylebedevs-MacBook-Pro bin % pyenv --version
pyenv 2.3.7
anatoly.lebedev@anatolylebedevs-MacBook-Pro bin % pyenv virtualenv --version
pyenv-virtualenv 1.1.5 (python -m venv)
anatoly.lebedev@anatolylebedevs-MacBook-Pro bin % pyenv global
tools
3.11.0
anatoly.lebedev@anatolylebedevs-MacBook-Pro bin % pyenv versions
  system
* 3.11.0 (set by /Users/anatoly.lebedev/.pyenv/version)
  3.11.0/envs/tools
* tools (set by /Users/anatoly.lebedev/.pyenv/version)

Here is a gist with debug info https://gist.github.com/albdv/d431df6c0d715aa31f9793f83d8e9323

native-api commented 1 year ago

@albdv If it's set to be global(ly selected), it's not supposed to be deactivating, ever. Why would it? You deactivate it, but then Pyenv-Virtualenv sees that it's the selected version so it activates it right back. That's exactly what I see happening in your trace.

native-api commented 1 year ago

If you need something else, you need to either unset it as the global version, or override the global version with pyenv local or pyenv shell.

stelah1423 commented 4 months ago

I ran into this exact issue.. What ended up working for me was running this from the directory where the virtualenv was setup:

pyenv deactivate .

Just running the command without the . gave me:

Failed to deactivate virtualenv.

Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.

Not sure why it thinks its not loaded properly, because it is afaik. 🤷‍♂️

nkrulikovsky commented 2 months ago

I ran into this exact issue.. What ended up working for me was running this from the directory where the virtualenv was setup:

pyenv deactivate .

Just running the command without the . gave me:

Failed to deactivate virtualenv.

Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.

Not sure why it thinks its not loaded properly, because it is afaik. 🤷‍♂️

Check if pyenv-virtualenv is initialized: Make sure that pyenv-virtualenv is correctly initialized in your shell's configuration file (like .bashrc, .zshrc, etc.). You should find lines similar to the following in your configuration file:

export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null && eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"