Search code examples
pythonpipenvpyenv

pipenv insists on installing Python 3.6


I set up my Python dev environment on macOS using the following commands:

brew install pyenv
pyenv install 3.7.0
pyenv install 2.7.15
pyenv global 3.7.0

I also added the following to my .bash_profile:

export PATH="/Users/me/.local/bin:$PATH"
eval "$(pyenv init -)"

Python seems to be working as expected:

01:29 $ python --version
Python 3.7.0

I then installed pipenv the "pragmatic" way, since installing via Homebrew would install a whole copy of Python as well (which I didn't want, since I was using pyenv already):

pip install --user pipenv

Now when I try to start a new pipenv project I get the following message:

01:28 $ mkdir my-new-project && cd my-new-project && pipenv install
Warning: Python 3.6 was not found on your system...
Would you like us to install CPython 3.6.6 with pyenv? [Y/n]:

I thought pipenv automatically used whatever pyenv copy of Python was available -- which is 3.7.0 in my case. Where is the prompt about installing CPython 3.6.6 coming from?


Solution

  • Short answer: if you're seeing weird behavior like this, run pipenv --support and read carefully.

    I had a stray Pipfile that was hanging out in the parent directory of my project that was dictating the version of Python to install. I'm guessing there's some sort of recursive search during pipenv install that looks for a Pipfile in any directory outside the current one.