Deactivate a pipenv environment
Python 3.xPipenvVirtual EnvironmentPython 3.x Problem Overview
How can I deactivate my pipenv environment?
With other tools I've been able to do something like source deactivate
, but that has no affect here.
Create an environment:
pipenv --three
Activate the environment:
source $(pipenv --venv)/bin/activate
But how to deactivate?
Python 3.x Solutions
Solution 1 - Python 3.x
To elaborate on Williams' answer a bit more, the expected workflow is to enter the virtualenv using pipenv shell
. When you activate the virtualenv that way, the console output now indicates to use exit
:
>Spawning environment shell (/bin/zsh). Use 'exit' to leave.
Trying to exit the virtualenv with deactivate
will leave pipenv in a confused state because you will still be in that spawned shell instance but not in an activated virtualenv.
Solution 2 - Python 3.x
Using the shell command exit
also works.
This worked for me when using deactivate
still left me with the error:
Shell for UNKNOWN_VIRTUAL_ENVIRONMENT already activated.
No action taken to avoid nested environments.
After using exit
I could successfully switch pipenv
instances. This could well be a bug and I should probably report it.
Solution 3 - Python 3.x
UPDATE: See other answers below. As it has been explained, this works for virtualenv
, but pipenv
works differently.
Just type deactivate
on the command line. See the guide here
Solution 4 - Python 3.x
Just type "exit", it will take you out of shell.
And if you use "deactivate", then probably you will get this error when you again try to enter in the shell.
Shell for UNKNOWN_VIRTUAL_ENVIRONMENT already activated.
No action taken to avoid nested environments.
So, it is prefer to use "exit" for quick access.
Solution 5 - Python 3.x
Please check this topic for answer from contributor perspective:
https://github.com/pypa/pipenv/issues/84#issuecomment-275056943
Spoiler :
> pipenv starts a new shell session with the virtualenv pathing instead of changing the pathing in the current shell session. That is why deactivate does not work. you need to exit the shell session. the exit command or CTRL-d will do the trick.
Solution 6 - Python 3.x
Deactivate from pipenv virtual environment, you can simply run the following command.
deactivate
Solution 7 - Python 3.x
for the problem caused was due to the previous shell operation in another directory so what i did was exiting my new directory by ctrl+d the exiting the terminal. After that i opened the terminal by alt+t build the directory to the intended directory.then run the pipenv shell command.
Solution 8 - Python 3.x
First "deactivate" and then "exit" you will get out of the virtual env. As of now this worked for me.