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

does not work with pyenv #145

Open
1 of 4 tasks
ConstantinoSchillebeeckx opened this issue Dec 4, 2020 · 7 comments
Open
1 of 4 tasks

does not work with pyenv #145

ConstantinoSchillebeeckx opened this issue Dec 4, 2020 · 7 comments
Labels

Comments

@ConstantinoSchillebeeckx
Copy link
Contributor

ConstantinoSchillebeeckx commented Dec 4, 2020

Issue Details

I'm having trouble getting this to work with pyenv. Though everything works generally, when I open a new window in an existing directory (shown as ~/Desktop/tmp in GIF), the env doesn't seem to be loading properly (see GIF below).

Operating System (uname -a)

Darwin CSchillebeeckx-0589.local 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64

zsh version (zsh --version)

zsh 5.7.1 (x86_64-apple-darwin19.0)

autoswitch-virtualenv version

3.1.0

How is zsh-autoswitch-virtualenv installed?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify)

Steps to reproduce the issue

Using pyenv 1.2.21

Untitled

@MichaelAquilina
Copy link
Owner

I dont use pyenv very often so it's very possible that I missed this bug. I'll try reproduce this bug and get back to you.

If I'm having trouble reproducing the issue I might ask if you could provide me a minimal zshrc that reproduces your isue

@dan-kez
Copy link

dan-kez commented Feb 6, 2021

+1 here - would excellent to have a pyenv addition here

@bolinocroustibat
Copy link

I'm using it with pyenv as well. I have other issues (not related to pyenv) but the env always does auto activate properly.

@MichaelAquilina
Copy link
Owner

So I've started using pyenv quite regularly and cant seem to reproduce the issue.

Does someone have a minimal zshrc I can use to try debug the issue?

@BenRoe
Copy link

BenRoe commented Jan 19, 2023

I have the problem, that the selected Python version with pyenv will not be used.

@ricky9w
Copy link

ricky9w commented Apr 15, 2023

@MichaelAquilina The problem seems to be in these lines:

if [[ ${params[(I)--verbose]} -eq 0 ]]; then
virtualenv $params "$(_virtual_env_dir "$venv_name")"
else
virtualenv $params "$(_virtual_env_dir "$venv_name")" > /dev/null
fi

This plugin uses the virtualenv command to create a virtual environment, but pyenv does not modify the corresponding path of virtualenv. By the way, pyenv has its own virtual environment tool called pyenv-virtualenv. You can use pyenv virtualenv <python_version> <environment_name> to call it. Therefore, the plugin still calls the system default virtualenv tool and creates a virtual environment based on the system Python version.

Fallback to the python -m venv <environment_name> command seems to solve the problem, but this will lose some great features provided by virtualenv.

Adding some optional parameters to call the pyenv virtualenv command when using pyenv to create a virtual environment may be a solution, but this will inevitably make the script more complex.

This requires some trade-offs.

@ricky9w
Copy link

ricky9w commented May 5, 2023

@MichaelAquilina The problem seems to be in these lines:

if [[ ${params[(I)--verbose]} -eq 0 ]]; then
virtualenv $params "$(_virtual_env_dir "$venv_name")"
else
virtualenv $params "$(_virtual_env_dir "$venv_name")" > /dev/null
fi

This plugin uses the virtualenv command to create a virtual environment, but pyenv does not modify the corresponding path of virtualenv. By the way, pyenv has its own virtual environment tool called pyenv-virtualenv. You can use pyenv virtualenv <python_version> <environment_name> to call it. Therefore, the plugin still calls the system default virtualenv tool and creates a virtual environment based on the system Python version.

Fallback to the python -m venv <environment_name> command seems to solve the problem, but this will lose some great features provided by virtualenv.

Adding some optional parameters to call the pyenv virtualenv command when using pyenv to create a virtual environment may be a solution, but this will inevitably make the script more complex.

This requires some trade-offs.

After using it for a few weeks, I found that there is no need to modify the code of the plugin itself. Just make sure to use the pip provided by pyenv when installing virtualenv. You can use python -m pip install virtualenv to ensure that pyenv's pip is used to install virtualenv. After installation, you can enter which virtualenv in the shell and expect to see an output similar to the following:

$ which virtualenv
/home/ricky/.pyenv/shims/virtualenv

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

No branches or pull requests

6 participants