Skip to content

Add 'pipenv activate' command for current shell activation#6494

Merged
matteius merged 1 commit intomainfrom
feature/pipenv-activate-2086
Dec 10, 2025
Merged

Add 'pipenv activate' command for current shell activation#6494
matteius merged 1 commit intomainfrom
feature/pipenv-activate-2086

Conversation

@matteius
Copy link
Copy Markdown
Member

Summary

This PR adds a new pipenv activate command that outputs the shell activation command, allowing users to activate the virtualenv in their current shell rather than spawning a subshell like pipenv shell does.

Motivation

This has been requested since 2018 (Issue #2086) with 20+ reactions. The current pipenv shell command spawns a nested subshell, which:

  • Creates nested shell sessions
  • Requires exit instead of deactivate to leave
  • Can interfere with shell customizations

The new approach is similar to:

  • Poetry's poetry env activate - Outputs a command to be eval'd
  • virtualenvwrapper's workon - Activates in current shell

Usage

# Bash/Zsh
$ eval $(pipenv activate)
(venv) $

# Fish
$ eval (pipenv activate)

# PowerShell
PS> Invoke-Expression (pipenv activate)

Users can create a convenient shell alias:

alias penv='eval $(pipenv activate)'

Example Output

$ pipenv activate
source /home/user/.virtualenvs/project-wR0g04D-/bin/activate

$ pipenv activate --help
Usage: pipenv activate [OPTIONS]

  Outputs the shell command to activate the virtualenv.

  Unlike 'pipenv shell' which spawns a subshell, this command prints the
  activation command that can be evaluated in your current shell.

  Usage examples:
      $ eval $(pipenv activate)          # Bash/Zsh
      $ eval (pipenv activate)           # Fish
      $ Invoke-Expression (pipenv activate)  # PowerShell

  You can create a shell alias for convenience:
      alias penv='eval $(pipenv activate)'

  This approach is similar to Poetry's 'poetry env activate' command.

Technical Details

  • Uses the existing _get_activate_script() function from shells.py
  • Detects the current shell type (bash, zsh, fish, csh, powershell, nu) and outputs the appropriate activation command
  • Outputs to stdout so it can be captured and eval'd

Fixes #2086


Pull Request opened by Augment Code with guidance from the PR author

Unlike 'pipenv shell' which spawns a subshell, 'pipenv activate' outputs
the shell command to activate the virtualenv in the current shell.

Usage:
    eval $(pipenv activate)          # Bash/Zsh
    eval (pipenv activate)            # Fish
    Invoke-Expression (pipenv activate)  # PowerShell

Users can create a convenient alias:
    alias penv='eval $(pipenv activate)'

This approach is similar to Poetry's 'poetry env activate' command and
addresses the long-standing request for virtualenvwrapper-like activation
behavior.

Fixes #2086
@matteius matteius merged commit 618e565 into main Dec 10, 2025
19 of 20 checks passed
@matteius matteius deleted the feature/pipenv-activate-2086 branch December 10, 2025 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

activate PIPENV_VENV_IN_PROJECT with --local

1 participant