Pipenv not recognizing Pyenv version?
There are several different directions in how to setup the .bashrc (even in the pyenv documentation). This one worked for me
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
Pipenv is aware of Pyenv, but it doesn't automatically use the same Python version unless you tell it to do that. There is a note about this in the Pipenv docs.
You can either tell Pipenv to use a specific Python version, like
pipenv install --python 3.6.5
or you can set an environment variable to default to the Pyenv version, like
export PIPENV_PYTHON="$PYENV_ROOT/shims/python"
In my case, on MacOS. I installed python 3.6.5 this way:
Install a specific python version using pyenv:
pyenv install 3.6.5
Create an environment using pipenv
with the --python
parameter along with the location of the python version:
pipenv --python /Users/<<Your_User>>/.pyenv/versions/3.6.5/bin/python3.6
If ever you encounter issues relating to _sqlite3
, you can check this pyenv ticket for the solution.
Use pipenv run
to execute commands inside the created environment:
pipenv run python manage.py shell
I noticed what the problem was after downgrading my system-wide Python from 3.7.0 to 3.6.5 and still getting the same error. Once pipenv
has created a virtualenv, it won't change it according to your current pyenv
version, but if you delete the virtualenv and create a new one, it will 'pick up' the correct version.