Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to deactivate current environment entered by pipenv shell? #84

Closed
jeyraof opened this issue Jan 25, 2017 · 37 comments
Closed

How to deactivate current environment entered by pipenv shell? #84

jeyraof opened this issue Jan 25, 2017 · 37 comments

Comments

@jeyraof
Copy link
Contributor

jeyraof commented Jan 25, 2017

❯ python -V
Python 2.7.10

❯ pipenv shell
Spawning environment shell (/bin/zsh).
source /Users/jeyraof/Work/fashion-keyword/.venv/bin/activate

❯ source /Users/jeyraof/Work/fashion-keyword/.venv/bin/activate

(fashion-keyword)❯ python -V
Python 3.6.0

(fashion-keyword)❯ deactivate

❯ python -V
Python 3.6.0

❯ exit

❯ python -V
Python 2.7.10

exit command is correct way to deactivate current environment?

@kfirbreger
Copy link

kfirbreger commented Jan 25, 2017

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.

@jeyraof
Copy link
Contributor Author

jeyraof commented Jan 26, 2017

@kfirbreger thank you!

@ebuildy
Copy link

ebuildy commented Jun 25, 2018

What about adding a pipenv exit to "close" the environment (so it can be documented).

@uranusjr
Copy link
Member

I do not think it is technically possible though; this is, like the activate script, not something we can hook into.

@ebuildy
Copy link

ebuildy commented Jun 26, 2018

Sorry, I was more thinking at a kind of alias: pipenv exit ==> exit, because pipenv help gives the way to activate an env. but no how to exit (yes developers are ... lazy ^^)

@uranusjr
Copy link
Member

@ebuildy Yeah, that would be very helpful, but as I said, it is not possible.

@clsource
Copy link

clsource commented Aug 10, 2018

@uranusjr
Maybe a message will be enough.
A simple reminder 👍

$ pipenv exit
if you need to exit the shell session. Use the exit command or press CTRL-d

@uranusjr
Copy link
Member

I would do that in a second, but it’s much more complicated than it sounds.

@pabrrs
Copy link

pabrrs commented Aug 16, 2018

exit work for me

@kfirbreger
Copy link

@abekroenem The request was for pipenv exit, which is quite different than exit. The later being a shell command which works, I believe similar to Ctrl-D. The former is where the complexity is at.

@oxfos
Copy link

oxfos commented Aug 18, 2018

I was looking for the same. Thank you for the answer.
My comments:

  1. I would at least add in the original documentation (https://docs.pipenv.org/) that exit is the command to deactivate/exit the virtual environment. I could only find that very briefly mentioned in the video but it is not written in the documentation.
  2. More importantly: People using virtualenv/virtualenvwrapper are used to use deactivate. If you type deactivate in pipenv - like above - you end up not seeing anymore the 'standard' text in parentheses (e.g. (fashion-keyword) above) that normally indicates you are in a virtual environment and you may think you are out of the virtual environment, which I understand it is not true. So why by using deactivate the text in parentheses is gone if we are still in the virtual environment? Wouldn't it be better to stay?

@kfirbreger
Copy link

kfirbreger commented Aug 18, 2018

@oxfos I am not an expert here, however:

  1. I think exit as the mechanism for exiting (and Ctrl-d for that matter) are not given much attention because that is the normal way to exit a shell. This is not unique to pipenv but works for any shell and iirc also screen, tux etc. Since you start a new shell, you exit it like any other shell, which is different than activating a virtualenv
  2. I believe pipenv uses virtualenv, which is why deactivate works, but it does not actually exit the shell. I agree that if you are thinking in terms of venvs while working with pipenv this can get confusing. However you should not be thinking in venvs as, like mentioned in 1, you are not activating a virtualenv (which basically played around with pathing) but instead starts a new shell session with the correct pathing.

Again, I am not an expert and I might be wrong so take this all with a grain of salt

@oxfos
Copy link

oxfos commented Aug 19, 2018

@kfirbreger
Thank you the specifications.
I think a more overt explanation would help, especially for people, like me, starting to learn Bash/Python.
And the second point is still not explained. In other words, if typing deactivate does not bring you out of the virtual environment/shell then the text in parentheses should not disappear, but it does.

@uranusjr
Copy link
Member

@kfirbreger Your observation is completely correct :)

@Bulletninja
Copy link

Typing deactivate worked for me.

@jongio
Copy link

jongio commented Sep 7, 2018

exit worked for me
deactivate did not

would be great to get this documented or added as pipenv exit to save the google.

@kennethreitz
Copy link
Contributor

it says it when you enter pipenv shell. read carefully :)

@jongio
Copy link

jongio commented Sep 7, 2018

Hmm, I didn't for me.

image

@techalchemy
Copy link
Member

This messaging seems to have been dropped somewhere when we realized we swapped out pew, @uranusjr wound up doing the final extraction of our patches and I assume we just overlooked this

@jongio
Copy link

jongio commented Sep 7, 2018

Would also be good to add it to docs or help output as well. That was the first place I went looking for it.

@kctong529
Copy link

It would be nice to also be included in The Hitchhiker's Guide to Python, where I came from. The use of pipenv above virtualenvwrapper was a bit unclear there.

@uranusjr
Copy link
Member

uranusjr commented Sep 30, 2018

@jongio The documentation is wide open for pull request. Submit one if you want to add things to it.

@kctong529 Please file an issue to that project instead. We don’t control what gets written there.

@EstebanBorai
Copy link

@kfirbreger Thanks so much!
I was having trouble with this message:

$pipenv shell
Shell for UNKNOWN_VIRTUAL_ENVIRONMENT already activated.
No action taken to avoid nested environments.

@muzi131313
Copy link

muzi131313 commented Nov 7, 2018

@EstebanBorai
after I execute command: deactivate, exist the following message:
image
same issues was here: pipenv-issues-736,
then I use exit command, everything was okay!

exit
pipenv shell

image

@tekNorah
Copy link

If anyone gets stuck with this one, try exiting twice, then load the shell.

@maxwaiyaki
Copy link

maxwaiyaki commented May 14, 2019

Typing deactivate worked for me.

This doesn't technically work. It seemingly "works" until you try to re-activate the virtual environment and you get this response:
Shell for UNKNOWN_VIRTUAL_ENVIRONMENT already activated. No action taken to avoid nested environments.

For an easy time, use exit or CTR + d to deactivate the virtual environment

@rjnfrazao
Copy link

rjnfrazao commented May 28, 2019

Great to find this discussion, I am facing similar problem, I will try those suggestions mentioned above. I believe there is still room for improvement on the management of virtual environments using pipenv. When I think I know what is going on, suddenly I got lost where I am.

I am starting to use Ubuntu via WSL, when I was creating my developing environment in Ubuntu, I executed "pipenv install --dev" to install all packages, I believe this command has also created my virtual environment. But in the end of the installation, I didn't get any "(virtual environment)" displayed at the command line. When I run "pipenv shell" to spawn the virtual environment, the error below is raised.

virtual environment error

Edited on 2019/05/29.
Although the message Shell for UNKNOWN_VIRTUAL_ENVIRONMENT already activated was displayed, the command deactivate was not found for me. To solve it ...

source /bin/activate -> after this command appeared my (virtual env) at the command line.
deactivate -> deactivate now worked
exit
pipenv shell -> Finally virtual environment was spawn as expected with my (virtual env) at prompt of the command line

But I am still confused though.

@jeyraof
Copy link
Contributor Author

jeyraof commented May 28, 2019

@rjnfrazao Have you tried pipenv run python3 manage.py runserver ?

@rjnfrazao
Copy link

rjnfrazao commented May 28, 2019

No. Many hanks for the suggestion. I will try it later. I didn't mention my following problem, but really appreciate your attention to go beyond my expectations. I believe this command would sort it out :

django error

I believe my case is explained and addressed in this issue: #3488

Edited on 2019/05/29

@jeyraof , it didn't work, actually as soon as my virtual environment was sorted out, at least I was able to execute the application using the python from my virtual env. However, I am facing another problem now. Well Keep walking. Thanks for info anyway.

@maxwellmckinnon
Copy link

New user of pipenv, spent 20 minutes trying to figure this out. The very good --help is misleading as I was expecting the information on how to do this to be buried here.

Perhaps add a hint to the help, as well as the message when trying to activate a shell when one has already been activated.

Current

pipenv shell
Shell for UNKNOWN_VIRTUAL_ENVIRONMENT already activated.
No action taken to avoid nested environments.

Proposed

pipenv shell
Shell for UNKNOWN_VIRTUAL_ENVIRONMENT already activated.
No action taken to avoid nested environments.
`exit` or CTRL-d to exit the current subshell

@abhikrni
Copy link

abhikrni commented Oct 7, 2019

Can anyone tell how do I re-activate it back again after I've exited out of the shell?

@frostming
Copy link
Contributor

@Abhishek5101 pipenv shell of course

@Hug0Albert0
Copy link

Try with deactivate or pipenv exit

@zaidsaeed
Copy link

If you are using jupyter-notebook, you might want to look into adding your venv as a kernel to jupyter. This link might help: http://queirozf.com/entries/jupyter-kernels-how-to-add-change-remove

@elcoach290
Copy link

what is the difference between exit and deactivate?

@Kokolokoli
Copy link

what is the difference between exit and deactivate?

checkout kfirbreger's comment. Exit is universal to shells, deactivate is specific to virtualenv!

@thebjko
Copy link

thebjko commented Apr 19, 2023

Where should I type exit?
Even though I get No virtualenv has been created for this project(/path/to/my/project/12_django_with_ajax) yet! Aborted! for pipenv --venv, I still get Shell for $HOME/.local/share/virtualenvs/12_django_with_ajax-c5EHbKKP already activated. No action taken to avoid nested environments. for pipenv shell.

pwd : /path/to/my/project/12_django_with_ajax

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

No branches or pull requests