4

I'm new to pipenv. I'm used to virtualenv, where I can source a script to "activate" the env in my current shell. Is there a way to use pipenv that way, rather than starting a subshell? I.e. source $(pipenv shell-env) or something like that? I'd like to have a linear shell history, not have to double-exit to exit the terminal window, etc. I'm using python 3.6 and 3.7 on Mac and Windows primarily.

GaryO
  • 5,873
  • 1
  • 36
  • 61
  • I suppose one could write a script to invoke the subshell, write the env out to a tmp file, and diff the two environments to produce a "source"able set of shell commands. Has anyone tried that? – GaryO Nov 12 '18 at 17:15
  • I have this exact same issue. Pipenv is a PITA with this. Needlessly creating a subshell that wreaks all kind of havoc with tmux `wait-for`s etc. Did you ever get around this? – Brad Jan 08 '19 at 16:51
  • Does this answer your question? [bash script starting new shell and continuing to run commands](https://stackoverflow.com/questions/48056606/bash-script-starting-new-shell-and-continuing-to-run-commands) – Jason Harrison Feb 24 '22 at 20:37
  • Nope -- the accepted answer is correct. You need to `source` the activate script. – GaryO Feb 26 '22 at 00:17

1 Answers1

5

On Linux or macOS:

source "$(pipenv --venv)/bin/activate"

On Windows (using bash; thanks @Nickolay):

source "$(pipenv --venv)/Scripts/activate"
codingjoe
  • 1,210
  • 15
  • 32