如何离开/退出/停用 Python virtualenv [英] How to leave/exit/deactivate a Python virtualenv

查看:88
本文介绍了如何离开/退出/停用 Python virtualenv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 virtualenv 和 virtualenvwrapper.我可以使用 workon 命令在 virtualenv 之间切换就好了.

I'm using virtualenv and the virtualenvwrapper. I can switch between virtualenv's just fine using the workon command.

me@mymachine:~$ workon env1
(env1)me@mymachine:~$ workon env2
(env2)me@mymachine:~$ workon env1
(env1)me@mymachine:~$ 

如何退出所有虚拟机并再次在我的真机上工作?现在,我回到 me@mymachine:~$ 的唯一方法是退出 shell 并启动一个新的 shell.这有点烦人.是否有无事可做"的命令,如果有,是什么?如果这样的命令不存在,我将如何创建它?

How do I exit all virtual machines and work on my real machine again? Right now, the only way I have of getting back to me@mymachine:~$ is to exit the shell and start a new one. That's kind of annoying. Is there a command to work on "nothing", and if so, what is it? If such a command does not exist, how would I go about creating it?

推荐答案

通常,激活一个 virtualenv 会给你一个 shell 函数,名为:

Usually, activating a virtualenv gives you a shell function named:

$ deactivate

让一切恢复正常.

我刚刚再次专门查看了 virtualenvwrapper 的代码,是的,它也支持 deactivate 作为逃避所有 virtualenv 的方式.

I have just looked specifically again at the code for virtualenvwrapper, and, yes, it too supports deactivate as the way to escape from all virtualenvs.

如果您想离开 Anaconda环境,命令取决于您的 conda 版本.最近的版本(如 4.6)直接在你的 shell 中安装一个 conda 函数,在这种情况下你运行:

If you are trying to leave an Anaconda environment, the command depends upon your version of conda. Recent versions (like 4.6) install a conda function directly in your shell, in which case you run:

conda deactivate

较旧的 conda 版本改为使用独立脚本实现停用:

Older conda versions instead implement deactivation using a stand-alone script:

source deactivate

这篇关于如何离开/退出/停用 Python virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆