-
-
Notifications
You must be signed in to change notification settings - Fork 422
.python-version activation doesn't set $VIRTUAL_ENV #348
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
Comments
For me this discovery came because I was trying to avoid the message about prompt changing being deprecated by adding the checks into my For anyone else in the same boat, here is the work-around I am currently using: if type "pyenv" > /dev/null 2>&1; then
local PYENV_VERSION_NAME=$(pyenv version-name)
if [[ ${PYENV_VERSION_NAME} != "system" ]]; then
PS1="(${PYENV_VERSION_NAME}) ${PS1}"
fi
fi Obviously, it makes a few assumptions:
|
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 |
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 |
Nope, I can't confirm this. VIRTUAL_ENV does not get set anymore, independently from the number of entries in |
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 To reproduce the coherence with the missing Just uncomment (activate) the line
and Poetry will behave as expected and install the dependencies in the current active venv (e.g. set by OK example which shows that Poetry is able to install the robotframework package into the venv: ❯ bash pyenv-poetry-test.sh create
❯ PWD = /Users/simon/Documents/01_Development/06_Minimalbeispiele
❯ Versions:
❯ pyenv: pyenv 2.3.2
❯ poetry: Poetry (version 1.2.0b2)
❯ pyenv global: system
❯ ---
❯ Tidying up
❯ Removing project
❯ Executing: rm -rf project
❯ Deleting pyenv-venv project
❯ Executing: pyenv virtualenv-delete -f project
-----
❯ Creating and entering project
❯ pyenv - create project: 'pyenv virtualenv 3.8.13 project'
Looking in links: /var/folders/pw/jgxh06cn3gs4_j7qqc31xn0w0000gn/T/tmp6j4htdzc
Requirement already satisfied: setuptools in /Users/simon/.pyenv/versions/3.8.13/envs/project/lib/python3.8/site-packages (56.0.0)
Requirement already satisfied: pip in /Users/simon/.pyenv/versions/3.8.13/envs/project/lib/python3.8/site-packages (22.0.4)
❯ pyenv - set local version: 'pyenv local project'
❯ pyenv - show local version: 'pyenv local'
project
❯ poetry - config:
cache-dir = "/Users/simon/Library/Caches/pypoetry"
experimental.new-installer = true
experimental.system-git-client = false
installer.max-workers = null
installer.no-binary = null
installer.parallel = true
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/simon/Library/Caches/pypoetry/virtualenvs
virtualenvs.prefer-active-python = false
virtualenvs.prompt = "{project_name}-py{python_version}"
❯ poetry - initialization: 'poetry init -n --name=project --python='^3.8' --dependency=robotframework'
Using version ^5.0.1 for robotframework
❯ poetry - install in pyenv: 'pyenv exec poetry install'
Using virtualenv: /Users/simon/.pyenv/versions/3.8.13/envs/project
Updating dependencies
Resolving dependencies...
1: fact: project is 0.1.0
1: derived: project
1: fact: project depends on robotframework (^5.0.1)
1: selecting project (0.1.0)
1: derived: robotframework (>=5.0.1,<6.0.0)
1: selecting robotframework (5.0.1)
1: Version solving took 0.020 seconds.
1: Tried 1 solutions.
Writing lock file
Finding the necessary packages for the current system
Package operations: 1 install, 0 updates, 0 removals
• Installing robotframework (5.0.1)
❯ Pip list:
Package Version
-------------- -------
pip 22.0.4
robotframework 5.0.1
setuptools 56.0.0 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 NOK example - watch the marked lines! ❯ bash pyenv-poetry-test.sh create
❯ PWD = /Users/simon/Documents/01_Development/06_Minimalbeispiele
❯ Versions:
❯ pyenv: pyenv 2.3.2
❯ poetry: Poetry (version 1.2.0b2)
❯ pyenv global: system
❯ ---
❯ Tidying up
❯ Removing project
❯ Executing: rm -rf project
❯ Deleting pyenv-venv project
❯ Executing: pyenv virtualenv-delete -f project
-----
❯ Creating and entering project
❯ pyenv - create project: 'pyenv virtualenv 3.8.13 project'
Looking in links: /var/folders/pw/jgxh06cn3gs4_j7qqc31xn0w0000gn/T/tmpjn51tc7x
Requirement already satisfied: setuptools in /Users/simon/.pyenv/versions/3.8.13/envs/project/lib/python3.8/site-packages (56.0.0)
Requirement already satisfied: pip in /Users/simon/.pyenv/versions/3.8.13/envs/project/lib/python3.8/site-packages (22.0.4)
❯ pyenv - set local version: 'pyenv local project'
❯ pyenv - show local version: 'pyenv local'
project
❯ poetry - config:
cache-dir = "/Users/simon/Library/Caches/pypoetry"
experimental.new-installer = true
experimental.system-git-client = false
installer.max-workers = null
installer.no-binary = null
installer.parallel = true
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/simon/Library/Caches/pypoetry/virtualenvs
virtualenvs.prefer-active-python = false
virtualenvs.prompt = "{project_name}-py{python_version}"
❯ poetry - initialization: 'poetry init -n --name=project --python='^3.8' --dependency=robotframework'
Using version ^5.0.1 for robotframework
❯ poetry - install in pyenv: 'pyenv exec poetry install'
Creating virtualenv project-snjECpG8-py3.9 in /Users/simon/Library/Caches/pypoetry/virtualenvs # ---<<<< ! < ! < ! < ! < ! < ! < !
Using virtualenv: /Users/simon/Library/Caches/pypoetry/virtualenvs/project-snjECpG8-py3.9 # ---<<<< ! < ! < ! < ! < ! < ! < !
Updating dependencies
Resolving dependencies...
1: fact: project is 0.1.0
1: derived: project
1: fact: project depends on robotframework (^5.0.1)
1: selecting project (0.1.0)
1: derived: robotframework (>=5.0.1,<6.0.0)
1: selecting robotframework (5.0.1)
1: Version solving took 0.031 seconds.
1: Tried 1 solutions.
Writing lock file
Finding the necessary packages for the current system
Package operations: 1 install, 0 updates, 0 removals
• Installing robotframework (5.0.1)
❯ Pip list: # lists the modules of the desired venv, but robotframework is missing (installed in Poetry's venv)---<<<< ! < ! < ! < ! < ! < ! < !
Package Version
---------- -------
pip 22.0.4
setuptools 56.0.0
# ---<<<< ! < ! < ! < ! < ! < ! < ! |
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) |
@simonmeggle are you maybe using the |
Make sure you have Pyenv and Pyenv-Virtualenv installed into the shell. To be able to set any envvars in the current shell, |
Turns out `VIRTUAL_ENV` needs to point to full env path (not just venv name). Details [here](pyenv/pyenv-virtualenv#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. Usingpyenv activate
, however, does set it. For example, suppose I have a folder/projects/my_project
with a.python-version
file containingmy_venv
. When Icd
into that folder, I can see that pyenv has properly detected the file and switched to usingmy_venv
by runningpyenv versions
:My shell's prompt (which checks for
${VIRTUAL_ENV}
) has not updated, and sure enough, runningecho ${VIRTUAL_ENV}
produces a blank line. If I runpyenv activate my_venv
, though, it all works as expected: pyenv picks it up andecho ${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 viapyenv activate
The text was updated successfully, but these errors were encountered: