pipenv icon indicating copy to clipboard operation
pipenv copied to clipboard

pipenv puts wrong python version in Pipfile, doesn't obey PIPENV_DEFAULT_PYTHON_VERSION

Open phette23 opened this issue 1 year ago • 0 comments

Issue description

pipenv install when not specifying a --python seems to create a venv with a different python version than what it uses in Pipfile and the Pipfile does not obey PIPENV_DEFAULT_PYTHON_VERSION.

> pipenv --version
pipenv, version 2023.8.23
> python --version
Python 3.9.13
> echo $PIPENV_DEFAULT_PYTHON_VERSION
3.9
> pipenv install
Creating a virtualenv for this project...
Pipfile: /Users/ephetteplace/Code/TEST/Pipfile
Using default python from /Users/ephetteplace/.pyenv/versions/3.9.13/bin/python3 (3.9.13) to create virtualenv...
⠸ Creating virtual environment...created virtual environment CPython3.9.13.final.0-64 in 1430ms
  creator CPython3Posix(dest=/Users/ephetteplace/.local/share/virtualenvs/TEST-BbsC0DfP, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/ephetteplace/Library/Application Support/virtualenv)
    added seed packages: pip==23.2.1, setuptools==68.1.2, wheel==0.41.2
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator

✔ Successfully created virtual environment!
Virtualenv location: /Users/ephetteplace/.local/share/virtualenvs/TEST-BbsC0DfP
Creating a Pipfile for this project...
Pipfile.lock not found, creating...
Locking [packages] dependencies...
Locking [dev-packages] dependencies...
Updated Pipfile.lock (415dfdcb118dd9bdfef17671cb7dcd78dbd69b6ae7d4f39e8b44e71d60ca72e7)!
Installing dependencies from Pipfile.lock (ca72e7)...
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
> grep version Pipfile
python_version = "3.6"

Expected result

Pipfile should use the version of the venv / PIPENV_DEFAULT_PYTHON_VERSION. In the example above, it should say python_version = "3.9".

Actual result

See above. Uses 3.6. I see here that "Pipenv by default uses the Python it is installed against to create the virtualenv". I don't think I installed pipenv with 3.6, that would have been a long time ago, but in any case it seems PIPENV_DEFAULT_PYTHON_VERSION should override this behavior. It is especially jarring to see pipenv use one version in the venv and another in the Pipfile.

Steps to replicate

I'm not 100% sure why this is happening. For me, the steps are just set -Ux PIPENV_DEFAULT_PYTHON_VERSION 3.9 && pipenv install (in fish). If the quote above about using the version it was installed against is correct, then more complete steps might look like

pyenv install 3.6
pyenv global 3.6
pip install pipenv
pyenv install 3.9
pyenv global 3.9
mkdir -p test && cd test
PIPENV_DEFAULT_PYTHON_VERSION=3.9 pipenv install

$ pipenv --support

Pipenv version: '2023.8.23'

Pipenv location: '/Users/ephetteplace/.pyenv/versions/3.9.13/lib/python3.9/site-packages/pipenv'

Python location: '/Users/ephetteplace/.pyenv/versions/3.9.13/bin/python3'

OS Name: 'posix'

User pip version: '23.2.1'

user Python installations found:

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '3.9.13',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '22.6.0',
 'platform_system': 'Darwin',
 'platform_version': 'Darwin Kernel Version 22.6.0: Wed Jul  5 22:21:56 PDT '
                     '2023; root:xnu-8796.141.3~6/RELEASE_X86_64',
 'python_full_version': '3.9.13',
 'python_version': '3.9',
 'sys_platform': 'darwin'}

System environment variables:

  • SHELL
  • PYENV_HOOK_PATH
  • ITERM_PROFILE
  • COLORTERM
  • PYENV_SHELL
  • XPC_FLAGS
  • TERM_PROGRAM_VERSION
  • __CFBundleIdentifier
  • TERM_SESSION_ID
  • HOMEBREW_PREFIX
  • EDITOR
  • PYENV_VERSION
  • PWD
  • LOGNAME
  • COMMAND_MODE
  • ITERM_SESSION_ID
  • HOME
  • LANG
  • TMPDIR
  • LC_TERMINAL
  • HOMEBREW_EDITOR
  • PYENV_DIR
  • TERM
  • USER
  • COLORFGBG
  • HOMEBREW_CELLAR
  • LC_TERMINAL_VERSION
  • DISPLAY
  • SHLVL
  • HOMEBREW_REPOSITORY
  • PIPENV_DEFAULT_PYTHON_VERSION
  • PYENV_ROOT
  • PATH
  • __CF_USER_TEXT_ENCODING
  • TERM_PROGRAM
  • PIP_DISABLE_PIP_VERSION_CHECK
  • PYTHONDONTWRITEBYTECODE
  • PYTHONFINDER_IGNORE_UNSUPPORTED

Pipenv–specific environment variables:

  • PIPENV_DEFAULT_PYTHON_VERSION: 3.9

Debug–specific environment variables:

  • PATH: /Users/ephetteplace/.pyenv/versions/3.6.9/bin:/Users/ephetteplace/.pyenv/versions/3.9.13/bin:/Users/ephetteplace/.pyenv/versions/3.5.10/bin:/Users/ephetteplace/.pyenv/versions/3.7.13/bin:/Users/ephetteplace/.pyenv/versions/3.11.4/bin:/Users/ephetteplace/.pyenv/versions/3.7.8/bin:/Users/ephetteplace/.pyenv/versions/3.9.13/bin:/usr/local/Cellar/pyenv/2.3.27/libexec:/usr/local/Cellar/pyenv/2.3.27/plugins/python-build/bin:/Users/ephetteplace/.pyenv/shims:/Users/ephetteplace/.rbenv/shims:/Users/ephetteplace/perl5/bin:/usr/local/sbin:/usr/local/opt/make/libexec/gnubin:/Users/ephetteplace/Library/pnpm:/Users/ephetteplace/bin/google-cloud-sdk/bin:/Users/ephetteplace/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/Library/Apple/usr/bin:/usr/local/MacGPG2/bin
  • SHELL: /usr/local/bin/fish
  • EDITOR: vim
  • LANG: en_US.UTF-8
  • PWD: /Users/ephetteplace/Code/TEST

Contents of Pipfile ('/Users/ephetteplace/Code/TEST/Pipfile'):

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.6"

Contents of Pipfile.lock ('/Users/ephetteplace/Code/TEST/Pipfile.lock'):

{
    "_meta": {
        "hash": {
            "sha256": "415dfdcb118dd9bdfef17671cb7dcd78dbd69b6ae7d4f39e8b44e71d60ca72e7"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.6"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {},
    "develop": {}
}

phette23 avatar Sep 20 '23 00:09 phette23