-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
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
- Open a terminal
- make sure your
SHELLisZSH - run
pipenv shellusingpipenv, version 2026.0.2or 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:
DISPLAYHOMELC_ALLLOGNAMEPATHSHELLTERMTMPDIRUSERSHLVLPWDOLDPWDZSHPAGERLESSLSCOLORSPYENV_ROOTHOMEBREW_PREFIXHOMEBREW_CELLARHOMEBREW_REPOSITORYINFOPATHHOMEBREW_EDITORVISUALEDITORHOMEBREW_INSTALL_CLEANUPPIP_DISABLE_PIP_VERSION_CHECKPIP_PYTHON_PATHPIPENV_PROJECT_DIRPS1_
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:/sbinSHELL:/bin/zshEDITOR:emacsPWD:[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"