I'm attempting to use pipenv and pyenv to create a virtual environment using python 3.9.0 for a project, but am not able to get pipenv to recognize the version of python 3.9.0 installed by pyenv. Oddly, using pyenv python 3.8.6 works just as expected, and I'm specifying the specific python I want pipenv to use, similar to this answer.
I'm running Catalina 10.15.7 and had a coworker reproduce this exact same behavior on his machine.
Both Pipenv and pyenv have been installed via Homebrew. I have since tried uninstalling homebrew Pipenv and reinstalling with pip, with the same results.
I successfully ran pyenv install 3.9.0
, and when I run pyenv versions
, I see:
Just as I'd expect.
Inside my working directory, I run pyenv local 3.9.0
to switch my local version of python, followed by pyenv version
, which returns returns:
3.9.0 (set by /Users/my-name/myproject)
indicating that the local version was set.
To double check, running pyenv which python
returns:
/Users/my-name/.pyenv/versions/3.9.0/bin/python
Now, if I run pipenv install --python 3.9.0
I get the following:
This already is suspect, since 3.9.0 is my local version already. If I respond with y
, I get:
Which seems odd, as when I run python
, I get to python 3.9.0, so clearly it is on my path. A Pipfile is not created for me, and I don't get a pipenv virtual environment.
Now, if instead I run pipenv install --python $PIPENV_PYTHON
, which should in theory use the version of python on my path (which, again, should be 3.9.0), I get this:
Notice how it says "using /users/..../python (3.9.0) to create virtualenv", which is correct, however the next line down says "created virtual environment CPYTHON3.8.6...".
Now, if I repeat the above steps using python 3.8.6, everything works fine.
Additionally, if I specify pipenv --python ~/.pyenv/versions/3.9.0/bin/python3.9
, that also seems to work fine -- so for some reason it's not respecting the version, but it is respecting the binary.
The same is true if I run pipenv install --python $(pyenv which python)
, since it's effectively the same thing as the above command.
For reference my environment vars:
PIP_PYTHON_PATH=/usr/local/Cellar/pipenv/2020.11.15/libexec/bin/python
<- perhaps this is a problem?
PIPENV_ACTIVE=1
PIPENV_PYTHON=/Users/myname/.pyenv/shims/python
PYENV_ROOT=/Users/myname/.pyenv
And my $PATH
starts with PATH=/Users/my-name/.pyenv/shims:
I do happen to have python 3.8 and python 3.9 installed via homebrew as well, however I'm not trying to use these, and since my path leads off with the shims, I feel like this should not be a problem. Running which python3
and which python
both point to the "shims" folder.
Pipenv is not respecting my pyenv shims, despite the fact that my PYENV_ROOT and my PATH are set correctly. Running pipenv install --python $(pyenv which python)
works, specifying a python version does not.
Is this a problem with pipenv, or pyenv, or something that I'm doing?
Per the pipenv docs:
Pipenv by default uses the Python it is installed against to create the virtualenv. You can set the
--python
option to$(pyenv which python)
to use your current pyenv interpreter.
It was probably using your system python versions rather than your shims
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With