Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pipenv using wrong python with pyenv #729

Closed
AlJohri opened this issue Sep 27, 2017 · 42 comments
Closed

pipenv using wrong python with pyenv #729

AlJohri opened this issue Sep 27, 2017 · 42 comments

Comments

@AlJohri
Copy link
Contributor

AlJohri commented Sep 27, 2017

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
$ which python
/Users/johria/.pyenv/shims/python
$ 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)
@nateprewitt
Copy link
Member

@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.

@audiolion
Copy link
Contributor

audiolion commented Sep 27, 2017

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

@AlJohri
Copy link
Contributor Author

AlJohri commented Sep 27, 2017

@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

@AlJohri
Copy link
Contributor Author

AlJohri commented Sep 27, 2017

@audiolion I do have python_requires in my Pipfile already:

[requires]
python_version = "3.6"

Still seems to be using the wrong version

@audiolion
Copy link
Contributor

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

@nateprewitt
Copy link
Member

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.

@kennethreitz
Copy link
Contributor

kennethreitz commented Sep 27, 2017

use python_full_version = "3.6.2".

@kennethreitz
Copy link
Contributor

See if that changes anything.

@AlJohri
Copy link
Contributor Author

AlJohri commented Sep 27, 2017

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

@AlJohri
Copy link
Contributor Author

AlJohri commented Sep 27, 2017

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.

@AlJohri
Copy link
Contributor Author

AlJohri commented Sep 27, 2017

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…

@AlJohri
Copy link
Contributor Author

AlJohri commented Sep 27, 2017

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.

@AlJohri
Copy link
Contributor Author

AlJohri commented Sep 27, 2017

Let me try python_full_version.

@AlJohri
Copy link
Contributor Author

AlJohri commented Sep 27, 2017

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.
.....

@kennethreitz
Copy link
Contributor

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

@kennethreitz
Copy link
Contributor

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

@AlJohri
Copy link
Contributor Author

AlJohri commented Sep 27, 2017

$ 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! 🎉

@AlJohri
Copy link
Contributor Author

AlJohri commented Sep 27, 2017

@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?

@AlJohri AlJohri closed this as completed Sep 27, 2017
@kennethreitz
Copy link
Contributor

sounds like it.

@kennethreitz
Copy link
Contributor

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.

@aleksijohansson
Copy link

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?

@uranusjr
Copy link
Member

uranusjr commented Apr 11, 2018

@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.

@aleksijohansson
Copy link

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

@joaqo
Copy link

joaqo commented Jul 6, 2018

@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!

@erinxocon
Copy link
Contributor

@techalchemy @uranusjr RE this behavior change

@techalchemy
Copy link
Member

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.

@uranusjr
Copy link
Member

uranusjr commented Jul 6, 2018

Someone integrate PythonFinder please!

@noodlebreak
Copy link

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.

@GerBreOwn
Copy link

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.

@kennethreitz
Copy link
Contributor

@GerBreOwn glad you fixed it!

@pearceeverydaylabs
Copy link

pearceeverydaylabs commented Jan 25, 2021

I believe this might actually be due to virtualenv caching python info and not realizing paths to executables can change in the presence of something like pyenv: #4431 (comment)

@lorengordon
Copy link

Started running into this also, in AWS CodeBuild, which uses pyenv. The project's Pipfile is only locked to python_version = "3", intentionally. The python version is controlled through the CodeBuild buildspec runtime-versions, instead.

pipenv kept selecting python 3.9, instead of the pyenv global python 3.8 version from the PATH, or pipenv's own runtime. This workaround gets me past the problem: pipenv --python=$(which python3)

@SergiyKolesnikov
Copy link

@lorengordon as kennethreitz42 mentioned

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

So, it looks like if you only specify python_version = "3" then pipenv takes the first version starting with 3 that it finds.

@lorengordon
Copy link

@SergiyKolesnikov I did see that, so I understand what is happening. Sorry, I only meant to offer a different workaround for others experiencing this issue. I had tried pipenv --python=$PYENV_ROOT/shims/python from this comment, but that didn't work for me because PYENV_ROOT is not in my env. pipenv --python=$(which python3) is what I ended up using, instead.

@praveen-git-code
Copy link

Hi All,

I am facing the same issue, when I try to run the make command, can any one help me to fix it.

Warning: Your Pipfile requires python_version 3.7, but you are using None (/home/s/.local/share/v/t/bin/python).
$ pipenv check will surely fail.
Loading .env environment variables…
Traceback (most recent call last):
File "/usr/bin//pipenv", line 11, in
load_entry_point('pipenv==11.9.0', 'console_scripts', 'pipenv')()
File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/lib/python3/dist-packages/pipenv/cli.py", line 505, in lock
core.ensure_project(three=three, python=python)
File "/usr/lib/python3/dist-packages/pipenv/core.py", line 616, in ensure_project
'{0}: Your Pipfile requires {1} {2}, '
TypeError: str returned non-string (type NoneType)
Traceback (most recent call last):
File "/usr/bin//pipenv", line 11, in
load_entry_point('pipenv==11.9.0', 'console_scripts', 'pipenv')()
File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/lib/python3/dist-packages/pipenv/cli.py", line 602, in run
core.do_run(command=command, args=args, three=three, python=python)
File "/usr/lib/python3/dist-packages/pipenv/core.py", line 2234, in do_run
os.execl(command_path, command_path, *args)
File "/usr/lib/python3.8/os.py", line 536, in execl
execv(file, args)
FileNotFoundError: [Errno 2] No such file or directory
make[2]: *** [Makefile:31: build_deploy] Error 1
make[2]: Leaving directory '/home/sg0309559/Linuxhome/REPO/aws-teardown-v2/aws-teardowns/functions/teardown_dispatcher'
make[1]: *** [Makefile:4: archive_teardown_dispatcher] Error 2
make[1]: Leaving directory '/home/sg0309559/Linuxhome/REPO/aws-teardown-v2/aws-teardowns/functions'
make: *** [Makefile:6: archive_lambdas] Error 2

@praveen-git-code
Copy link

@AlJohri Please guide me how you did it

@SergiyKolesnikov
Copy link

;TLDR for those who ran into this problem:

pipenv --rm
pipenv install --python V

Replace V with the value of the python_version parameter from your Pipfile

If you are just starting a new project and do not have a Pipfile yet, replace V with the Python version that you set up for this project with asdf, pyenv, or whatever tool you are using to manage Python versions.

@HakunMatat4
Copy link

$ 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! tada

Your 2017 fix, helped a 2021 problem :)

@seankamugasa
Copy link

Thank you.

@iQiexie
Copy link

iQiexie commented Jan 30, 2023

Hello, my system python version is 3.10, but I wanna run python 3.6 project and I can't figure out how to

$ pipenv --rm                

Loading .env environment variables...
Removing virtualenv (/Users/roman/.local/share/virtualenvs/arkoil-3G2nlaxt)...
$ python3 --version 
Python 3.10.7
$ python3.6 --version               
Python 3.6.8
$ pipenv --python=$(which python3.6)

Loading .env environment variables...
Warning: the environment variable LANG is not set!
We recommend setting this in ~/.profile (or equivalent) for proper expected behavior.
Creating a virtualenv for this project...
Pipfile: /Users/roman/Desktop/pycharm_projects/arkoil/Pipfile
Using /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 (3.6.8) to create virtualenv...
⠼ Creating virtual environment...created virtual environment CPython3.6.8.final.0-64 in 263ms
  creator CPython3Posix(dest=/Users/roman/.local/share/virtualenvs/arkoil-3G2nlaxt, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/roman/Library/Application Support/virtualenv)
    added seed packages: pip==21.3.1, setuptools==59.6.0, wheel==0.37.1
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
✔ Successfully created virtual environment! 
Virtualenv location: /Users/roman/.local/share/virtualenvs/arkoil-3G2nlaxt
$ pipenv shell

Loading .env environment variables...
Loading .env environment variables...
Launching subshell in virtual environment...
 . /Users/roman/.local/share/virtualenvs/arkoil-3G2nlaxt/bin/activate
roman@romans-MacBook-Air arkoil %  . /Users/roman/.local/share/virtualenvs/arkoil-3G2nlaxt/bin/activate
$ (arkoil) python --version
Python 3.6.8
$ (arkoil) pipenv install

Loading .env environment variables...
Pipfile.lock not found, creating...
Locking [packages] dependencies...
Building requirements...
✘ Locking Failed! 

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/pipenv/2022.9.24/libexec/lib/python3.10/site-packages/pipenv/resolver.py", line 816, in <module>
    main()
  File "/opt/homebrew/Cellar/pipenv/2022.9.24/libexec/lib/python3.10/site-packages/pipenv/resolver.py", line 790, in main
    _ensure_modules()
  File "/opt/homebrew/Cellar/pipenv/2022.9.24/libexec/lib/python3.10/site-packages/pipenv/resolver.py", line 16, in _ensure_modules
    spec.loader.exec_module(pipenv)
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/opt/homebrew/Cellar/pipenv/2022.9.24/libexec/lib/python3.10/site-packages/pipenv/__init__.py", line 58, in <module>
    from .cli import cli
  File "/opt/homebrew/Cellar/pipenv/2022.9.24/libexec/lib/python3.10/site-packages/pipenv/cli/__init__.py", line 1, in <module>
    from .command import cli  # noqa
  File "/opt/homebrew/Cellar/pipenv/2022.9.24/libexec/lib/python3.10/site-packages/pipenv/cli/command.py", line 7, in <module>
    from pipenv.cli.options import (
  File "/opt/homebrew/Cellar/pipenv/2022.9.24/libexec/lib/python3.10/site-packages/pipenv/cli/options.py", line 3, in <module>
    from pipenv.project import Project
  File "/opt/homebrew/Cellar/pipenv/2022.9.24/libexec/lib/python3.10/site-packages/pipenv/project.py", line 1
    from __future__ import annotations
    ^
SyntaxError: future feature annotations is not defined

@seankamugasa
Copy link

You can run a Python 3.6 project on your Python 3.10 system in several ways:

  1. Create a virtual environment with Python 3.6: This will allow you to run the project in an isolated environment with the specific version of Python you need.
    OR

  2. Use a version manager like pyenv or conda: These tools let you switch between different Python versions on your system, so you can run your Python 3.6 project without affecting other projects.
    OR

  3. Run the project in a Docker container: This allows you to run the project in an isolated environment with the specific version of Python you need.

OR

  1. Simply use poetry by following this link
    https://stackoverflow.com/questions/60580113/change-python-version-to-3-x

@matteius
Copy link
Member

Pipenv no longer supports python 3.6

@pypa pypa locked as resolved and limited conversation to collaborators Jan 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests