Skip to content

#6462 introduced a bug on ZSH with the pipenv shell subcommand #6503

@retornam

Description

@retornam

Issue description

#6462 introduced an error on ZSH shells when running the pipenv shell command specifically this line

https://github.com/pypa/pipenv/blame/c05edc9e2572630fc3da45827658d92fc7f72572/pipenv/shells.py#L108-L113C7 returns the following error on ZSH

eval "_pipenv_old_deactivate() { $(declare -f deactivate | tail -n +2) }";
zsh: parse error near `}'

The primary issue here lies in the fact that ZSH exhibits a different behavior compared to BASH. This discrepancy arises from how ZSH expands the commands contained in $() prior to parsing the deactivate function’s body. Thus, the command $(declare -f deactivate | tail -n +2) leads to a parse error.

This can be tested with the simple test case below

#!/bin/zsh

a() { echo hi; }

eval "b() { $(declare -f a | tail -n +2) }"

which results in

(eval):2: parse error near `}'

compared to BASH which works

#!/bin/bash

a() { echo hi; }

eval "b() { $(declare -f a | tail -n +2) }"

Expected result

➜ pipenv shell
Launching subshell in virtual environment...
 source [redacted]/.local/share/virtualenvs/ptest-e-Sh59uF/bin/activate
➜

This should work without failing

Actual result

pipenv shell
Launching subshell in virtual environment...
 source [redacted]/.local/share/virtualenvs/ptest-e-Sh59uF/bin/activate
eval "_pipenv_old_deactivate() { $(declare -f deactivate | tail -n +2) }"; deactivate() { _pipenv_old_deactivate; unset PIPENV_ACTIVE; }
➜  source [redacted]/.local/share/virtualenvs/ptest-e-Sh59uF/bin/activate
➜  eval "_pipenv_old_deactivate() { $(declare -f deactivate | tail -n +2) }"; deactivate() { _pipenv_old_deactivate; unset PIPENV_ACTIVE; }
zsh: parse error near `}'

Steps to replicate

  1. Open a terminal
  2. make sure your SHELL is ZSH
  3. run pipenv shell using pipenv, version 2026.0.2 or any branch that contains the PR Fix PIPENV_ACTIVE not being unset on deactivate #6462

Provide the steps to replicate (which usually at least includes the commands and the Pipfile).


Please run $ pipenv --support, and paste the results here. Don't put backticks (`) around it! The output already contains Markdown formatting.

$ pipenv --support

Pipenv version: '2026.0.2'

Pipenv location: '/opt/homebrew/Cellar/pipenv/2026.0.2/libexec/lib/python3.14/site-packages/pipenv'

Python location: '/opt/homebrew/Cellar/pipenv/2026.0.2/libexec/bin/python'

OS Name: 'posix'

User pip version: '25.3'

user Python installations found:

  • 3.14.2: /opt/homebrew/bin/python3

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '3.14.2',
 'os_name': 'posix',
 'platform_machine': 'arm64',
 'platform_python_implementation': 'CPython',
 'platform_release': '24.6.0',
 'platform_system': 'Darwin',
 'platform_version': 'Darwin Kernel Version 24.6.0: Wed Nov  5 21:32:56 PST '
                     '2025; root:xnu-11417.140.69.705.2~1/RELEASE_ARM64_T8103',
 'python_full_version': '3.14.2',
 'python_version': '3.14',
 'sys_platform': 'darwin'}

System environment variables:

  • DISPLAY
  • HOME
  • LC_ALL
  • LOGNAME
  • PATH
  • SHELL
  • TERM
  • TMPDIR
  • USER
  • SHLVL
  • PWD
  • OLDPWD
  • ZSH
  • PAGER
  • LESS
  • LSCOLORS
  • PYENV_ROOT
  • HOMEBREW_PREFIX
  • HOMEBREW_CELLAR
  • HOMEBREW_REPOSITORY
  • INFOPATH
  • HOMEBREW_EDITOR
  • VISUAL
  • EDITOR
  • HOMEBREW_INSTALL_CLEANUP
  • PIP_DISABLE_PIP_VERSION_CHECK
  • PIP_PYTHON_PATH
  • PIPENV_PROJECT_DIR
  • PS1
  • _

Pipenv–specific environment variables:

  • PIPENV_PROJECT_DIR: [REDACTED]/ptest

Debug–specific environment variables:

  • PATH: /opt/homebrew/bin:/opt/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin
  • SHELL: /bin/zsh
  • EDITOR: emacs
  • PWD: [REDACTED]/ptest

Contents of Pipfile ('[REDACTED]/Pipfile'):

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

[packages]

[dev-packages]

[requires]
python_version = "3"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions