Issue
I am using pyenv to manage different Python versions on my machine, and href="https://github.com/pyenv/pyenv-virtualenv" rel="nofollow noreferrer">pyenv-virtualenv to manage my venvs. When I create a new venv with something like pyenv virtualenv foo
it doesn't install the latest version of pip
, setuptools
, and wheel
into the venv. I would like to run pip install --upgrade pip setuptools wheel
inside each venv after it has been created.
pyenv has the concept of hooks for before and after a command. I am able to run this command by adding the following file
~/.pyenv/plugins/pyenv-virtualenv/etc/pyenv.d/virtualenv/after.bash
with the following contents
after_virtualenv 'pip install --upgrade pip setuptools wheel'
The command is run, but it is not run inside the venv, so it just uses the current pip
. How can I call this command inside the venv in the after_virtualenv hook?
Solution
Okay I figured it out you can just specify just created virtualenv name as the PYENV_VERSION and call pyenv-exec
.
upgrade_packages() {
PYENV_VERSION=$VIRTUALENV_NAME pyenv-exec pip install --upgrade pip setuptools wheel
}
after_virtualenv 'upgrade_packages'
Answered By - Ross MacArthur Answer Checked By - Timothy Miller (WPSolving Admin)