pipenv using wrong python with pyenv

Created on 27 Sep 2017  Ā·  30Comments  Ā·  Source: pypa/pipenv

pipenv is using python 3.5.3 instead of 3.6.2 for some reason

$ pipenv --version
pipenv, version 8.0.7
$ python --version
Python 3.6.2



md5-02ec54844cc8bc0d1d191cc30160079f



$ which python
/Users/johria/.pyenv/shims/python



md5-02ec54844cc8bc0d1d191cc30160079f



$ pipenv install --dev
Creating a virtualenv for this projectā€¦
ā ‹Using base prefix '/Users/johria/.pyenv/versions/3.5.3'
New python executable in /Users/johria/.local/share/virtualenvs/context-generator-d3x1ENAX/bin/python3.5
Also creating executable in /Users/johria/.local/share/virtualenvs/context-generator-d3x1ENAX/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /Users/johria/.local/share/virtualenvs/context-generator-d3x1ENAX
Installing dependencies from Pipfile.lockā€¦
  šŸ   ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ 25/25 ā€” 00:00:44
To activate this project's virtualenv, run the following:
 $ pipenv shell
$ pyenv versions
  system
  2.7.13
  3.5.3
* 3.6.2 (set by /Users/johria/Development/heliograf/apps/context-generator/.python-version)

Most helpful comment

$ pipenv --rm
$ pipenv install
$ Creating a virtualenv for this projectā€¦
Using /Users/johria/.pyenv/versions/3.6.2/bin/python3.6m to create virtualenvā€¦

fixed! thank you all! šŸŽ‰

All 30 comments

@AlJohri what is the value returned from python3 --version? Also do you have python_requires in your Pipfile?

It looks like you have pyenv configured to give 3.5 precedence for python3.

pipenv doesn't look at .python-version or runtime.txt files to determine which python version to look for, as @nateprewitt mentioned add python_requires to your Pipfile, otherwise be explicit: pipenv --python 3.6.2 install --dev

@nateprewitt It's 3.6.2.

My global python is also not 3.5.2, it is:

$ pyenv versions
  system
* 2.7.13 (set by /Users/johria/.pyenv/version)
  3.5.3
* 3.6.2 (set by /Users/johria/.pyenv/version)
$ cat ~/.pyenv/version
3.6.2:2.7.13

@audiolion I do have python_requires in my Pipfile already:

[requires]
python_version = "3.6"

Still seems to be using the wrong version

Ok if you have python_version in there then it looks like a bug. I don't think pipenv respects what version pyenv has set, and uses the system so python3 --version would tell you what pipenv looks for, it could be that pipenv isn't finding the pyenv shims and so decides to use 3.5 because its all it can find? seems like it still shouldn't do that

I'm not at a computer right now so I can't test this out but this sounds like either a very recent regression or some sort of configuration hiccup on your machine. I look at this tonight if no one else gets it first.

use python_full_version = "3.6.2".

See if that changes anything.

Pipfile and Pipfile.lock: https://gist.github.com/AlJohri/7e7b68ddad1f9ac6cb1c64dbc8a45670

$ which python
/Users/johria/.pyenv/shims/python
$ which python2
/Users/johria/.pyenv/shims/python2
$ which python3
/Users/johria/.pyenv/shims/python3
$ python --version
Python 3.6.2
cat .python-version
3.6.2

(python2: command not found is due to the .python-version file)

$ python2 --version
pyenv: python2: command not found

The `python2' command exists in these Python versions:
  2.7.13
$ python3 --version
3.6.2

wait, I'm sorry - It seems I was looking at the wrong Pipfile - I didn't have python_requires in this one. Fixing and trying again.

Yeah, it still seems like there's a bug somewhere but it gave me a proper message now:

$ pipenv install
Warning: Your Pipfile requires python_version 3.6, but you are using 3.5.3 (/Users/johria/.local/share/v/c/bin/python).
  $ pipenv check will surely fail.
Pipfile.lock out of date, updatingā€¦
Locking [dev-packages] dependenciesā€¦
Locking [packages] dependenciesā€¦
Updated Pipfile.lock!
Installing dependencies from Pipfile.lockā€¦

The confusing part is that I don't have 3.5.3 set anywhere - I pretty much don't use it. It's not in my global pyenv or local.

@audiolion yeah, sorry I was looking at an incorrect Pipfile - I posted the updated message above https://github.com/kennethreitz/pipenv/issues/729#issuecomment-332543907.

Let me try python_full_version.

Same message:

$ pipenv install
Warning: Your Pipfile requires python_version 3.6, but you are using 3.5.3 (/Users/johria/.local/share/v/c/bin/python).
  $ pipenv check will surely fail.
.....

We search through all Pythons that Pyenv has installed, and look for effectively (python --version).startswith(your_version), and return that.

you'll have to do a pipenv --rm to start over.

$ pipenv --rm
$ pipenv install
$ Creating a virtualenv for this projectā€¦
Using /Users/johria/.pyenv/versions/3.6.2/bin/python3.6m to create virtualenvā€¦

fixed! thank you all! šŸŽ‰

@kennethreitz so the odd behavior was because it was using the first python that starts with python "3" by default since I didn't have python_version or python_full_version?

sounds like it.

you need to be specific if you want us to be specific :)

We can introduce ordering eventually, but it'll slow things down a little bit.

I propose honouring either the .python-version or python --version or anything else that would make pipenv use the currently active python instead of picking the first python3 it finds. Should I open a new issue for this instead of continuing this existing one?

@aleksijohansson The .python-version proposal was already rejected a while ago because we want to avoid supporting non-standard stuff if possible. Use pipenv --python=$PYENV_ROOT/shims/python if you want to hook into the .python-version configuration.

@uranusjr I understand and that makes sense. Relying on python --version could be good though. Thanks for the suggested workaround!

@kennethreitz I noticed you mentioned that you look for the highest python version pyenv has installed and default to that. I think it could make sense to check if there is a system python version higher than the pyenv pythons too.

I only use pyenv to install old python versions and pipenv defaulted to using one of those instead of my systems python3.6 install, which was quite unexpected as user and gave me a bit of a debugging session. Thanks for the great project btw!

@techalchemy @uranusjr RE this behavior change

Would be nice, is much harder than it sounds. We have a library for this which actually handles it correctly but integration into the codebase is a huge hurdle.

Someone integrate PythonFinder please!

I do this:

/home/ubuntu/morpheus$ pipenv install --python=3.6
Virtualenv already exists!
Removing existing virtualenvā€¦
Virtualenv already exists!
Removing existing virtualenvā€¦
Virtualenv already exists!
Removing existing virtualenvā€¦
Virtualenv already exists!
Removing existing virtualenvā€¦
Virtualenv already exists!
Removing existing virtualenvā€¦
Virtualenv already exists!
Removing existing virtualenvā€¦
Virtualenv already exists!
Removing existing virtualenvā€¦
Virtualenv already exists!
Removing existing virtualenvā€¦
Virtualenv already exists!
Removing existing virtualenvā€¦
Virtualenv already exists!
Removing existing virtualenvā€¦
Virtualenv already exists!
Removing existing virtualenvā€¦
Virtualenv already exists!
Removing existing virtualenvā€¦

Even though Python 3.6 exists.

I just upgraded my Python from 3.7.1 to 3.7.2 and I started having problem. My simple solution was to run "pipenv rm" and then "pipenv install -r requirements.txt" and the Python in the virtualenv has been updated to 3.7.2, which is what I wanted.

@GerBreOwn glad you fixed it!

Was this page helpful?
0 / 5 - 0 ratings