Deactivate a pipenv environment

坚强是说给别人听的谎言 提交于 2020-11-30 04:54:32

问题


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?


回答1:


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




回答2:


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.




回答3:


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.




回答4:


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.




回答5:


First "deactivate" and then "exit" you will get out of the virtual env. As of now this worked for me.



来源:https://stackoverflow.com/questions/49944871/deactivate-a-pipenv-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!