You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.python-version activation doesn't set $VIRTUAL_ENV #348
Perhaps I am missing something, but when I use a .python-version file to activate virtual environments, the $VIRTUAL_ENV variable isn't set. Using pyenv activate, however, does set it. For example, suppose I have a folder /projects/my_project with a .python-version file containing my_venv. When I cd into that folder, I can see that pyenv has properly detected the file and switched to using my_venv by running pyenv versions:
me@my_system$ pyenv versions system 3.8.2* my_venv (set by /projects/my_project/.python-version)
My shell's prompt (which checks for ${VIRTUAL_ENV}) has not updated, and sure enough, running echo ${VIRTUAL_ENV} produces a blank line. If I run pyenv activate my_venv, though, it all works as expected: pyenv picks it up and echo ${VIRTUAL_ENV} returns /Users/me/.pyenv/versions/3.8.2/env/my_venv
Given the verbiage in the README ("pyenv-virtualenv will automatically activate/deactivate virtualenvs on entering/leaving directories which contain a .python-version file that contains the name of a valid virtual environment") I expected VIRTUAL_ENV to be set as it is via pyenv activate
Reacted by Skurikhin Alexandr, darkfishy, tony-bony, Brad Solomon, Mark Macdonald, Yang Li, James Marchant, Hubert Behaghel, Chen Ye, Trong-Lanh, Rémi Nɢᴜʏᴇɴ and 8 more
For me this discovery came because I was trying to avoid the message about prompt changing being deprecated by adding the checks into my .bashrc file. I originally checked for the VIRTUAL_ENV variable, but found that it wouldn't actually match what pyenv was doing.
For anyone else in the same boat, here is the work-around I am currently using:
This issue also interferes with pipenv, which expects this env variable to be set, in order to use existing virtual environment. Otherwise, pipenv keeps creating a new virtual environment (that is its default behaviour)
I am not sure how helpful this is but if you keep only one line in your .python-version, the one with the virtualenv name, and delete any other (python version numbers), then it automatically sets $VIRTUAL_ENV.
I know this issue has been opened a long time ago. But it used to work perfectly for me, and now it seems like the $VIRTUAL_ENV variable is not set anymore? I am using fish as my shell, maybe it matters?
I am not sure how helpful this is but if you keep only one line in your .python-version, the one with the virtualenv name, and delete any other (python version numbers), then it automatically sets $VIRTUAL_ENV.
Nope, I can't confirm this. VIRTUAL_ENV does not get set anymore, independently from the number of entries in .python-version
Now the same, but without setting the VIRTUAL_ENV var:
# ### WITHOUT THIS VARIABLE, POETRY WON'T USE THE VIRTUALENV VERSION SET FOR THIS FOLDER #### (it will prepare the venv in the "poetry way")# export VIRTUAL_ENV=$(pyenv virtualenv-prefix)/envs/$PYENV_VENV_NAME
I was running into this issue, I was just able to resolve it by following the instructions in the README about enabling automatic activation of virtualenvs (step 2 under Installing as a pyenv plugin)
Reacted by Simon Meggle, Teresa-AlliedVision, Maks Naumenko, Dustin Winslow, jaydm26 and Jooeon Kim
@simonmeggle are you maybe using the precmd/precwd workaround from #259? I've noticed that that workaround unfortunately leads to VIRTUAL_ENV not being set correctly
Make sure you have Pyenv and Pyenv-Virtualenv installed into the shell.
(Check the README or pyenv init and pyenv virtualenv-init output for installation instructions.)
To be able to set any envvars in the current shell, pyenv must be a shell function. And Pyenv-Virtualenv's init code needs to have been run to invoke activation logic when the selected version is a virtualenv -- which is different from regular version selection logic.
Activity
Tsubashi commentedon Apr 9, 2020
For me this discovery came because I was trying to avoid the message about prompt changing being deprecated by adding the checks into my
.bashrcfile. I originally checked for theVIRTUAL_ENVvariable, but found that it wouldn't actually match what pyenv was doing.For anyone else in the same boat, here is the work-around I am currently using:
Obviously, it makes a few assumptions:
systemsystempythondarkfishy commentedon May 12, 2020
This issue also interferes with pipenv, which expects this env variable to be set, in order to use existing virtual environment. Otherwise, pipenv keeps creating a new virtual environment (that is its default behaviour)
behaghel commentedon Dec 27, 2020
I am not sure how helpful this is but if you keep only one line in your
.python-version, the one with the virtualenv name, and delete any other (python version numbers), then it automatically sets $VIRTUAL_ENV.dcupif commentedon May 5, 2022
I know this issue has been opened a long time ago. But it used to work perfectly for me, and now it seems like the
$VIRTUAL_ENVvariable is not set anymore? I am usingfishas my shell, maybe it matters?simonmeggle commentedon Jul 8, 2022
Nope, I can't confirm this. VIRTUAL_ENV does not get set anymore, independently from the number of entries in
.python-versionsimonmeggle commentedon Jul 8, 2022
I am coming from this issue at python-poetry and wanted to find out why Poetry installs dependencies as if there were no active venv at all.
OS: Monterey 12.2, ARM64E
Shell: zsh
To reproduce the coherence with the missing
VIRTUAL_ENVvariable I have written a small script.Just uncomment (activate) the line
and Poetry will behave as expected and install the dependencies in the current active venv (e.g. set by
.python_version).OK example which shows that Poetry is able to install the robotframework package into the venv:
Now the same, but without setting the VIRTUAL_ENV var:
NOK example - watch the marked lines!
nint8835 commentedon Oct 20, 2022
I was running into this issue, I was just able to resolve it by following the instructions in the README about enabling automatic activation of virtualenvs (step 2 under Installing as a pyenv plugin)
hassec commentedon Sep 10, 2023
@simonmeggle are you maybe using the
precmd/precwdworkaround from #259? I've noticed that that workaround unfortunately leads toVIRTUAL_ENVnot being set correctlynative-api commentedon Dec 24, 2024
Make sure you have Pyenv and Pyenv-Virtualenv installed into the shell.
(Check the README or
pyenv initandpyenv virtualenv-initoutput for installation instructions.)To be able to set any envvars in the current shell,
pyenvmust be a shell function. And Pyenv-Virtualenv's init code needs to have been run to invoke activation logic when the selected version is a virtualenv -- which is different from regular version selection logic.chore(zsh): fixed python virtualenv setup