【问题标题】:python `deactivate` command can't exit virtualenvpython`deactivate`命令无法退出virtualenv
【发布时间】:2020-02-10 11:33:50
【问题描述】:

我使用的是 macOS Catalina [10.15]。这是我尝试停用时得到的结果:

(django-learning) ~/git/stats-k8s/k8s-monitor (master) $ deactivate
DeprecationWarning: 'source deactivate' is deprecated. Use 'conda deactivate'.
(django-learning) ~/git/stats-k8s/k8s-monitor (master) $
(django-learning) ~/git/stats-k8s/k8s-monitor (master) $
(django-learning) ~/git/stats-k8s/k8s-monitor (master) $
(django-learning) ~/git/stats-k8s/k8s-monitor (master) $ conda deactivate

CommandNotFoundError: Your shell has not been properly configured to use 'conda deactivate'.
To initialize your shell, run
...    
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
(django-learning) ~/git/stats-k8s/k8s-monitor (master) $

我已经看过问题:How to leave/exit/deactivate a Python virtualenv 但没有帮助。

【问题讨论】:

  • 这看起来你使用的是conda,而不是标准的virtualenv
  • 您是否首先使用 conda 或 virtualenv 激活了这个环境?这些不是一回事。
  • 刚刚发现问题出在一个 shell [我已经退出了]。可能是因为我试图使用 direnv 激活和停用我的 virtualenv。

标签: python virtualenv virtualenvwrapper


【解决方案1】:

我怀疑 conda 正在干扰您的设置中的 virtualenv。你在 virtualenv 中安装 conda 了吗?

请注意,您也可以安全地关闭终端窗口并打开一个新窗口,而无需使用deactivate

您也可以尝试激活不同的虚拟环境。您可以在不先停用的情况下执行此操作。然后,您也许可以从其他环境中停用。

【讨论】:

  • 至少对于具有 POSIX-y shell 的系统上的上游 virtualenv(不能与 conda 对话,OP 的输出暗示他们正在使用),deactivate 是一个 shell 函数,activate定义;它不是一个单独的脚本。
  • 它在 Windows 上,有趣。
  • 正如@CharlesDuffy 提到的,我可以在 /bin 文件夹中找到一个停用脚本。
  • @gilch,这是有道理的,因为在 Windows 中,批处理文件是在进程中执行的(在 UNIX 世界中,您必须使用 source 或等效项)。
猜你喜欢
  • 2019-08-07
  • 2017-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-03
  • 2018-03-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多