在Windows上,在PyCharm的Git-Bash控制台中手动激活虚拟环境后,Bash命令丢失(bash:command not found)。

17 浏览
0 Comments

在Windows上,在PyCharm的Git-Bash控制台中手动激活虚拟环境后,Bash命令丢失(bash:command not found)。

在Windows上将Git-Bash嵌入PyCharm(2019.1.3 CE)后,按照这个线程(或这个)的方法,我在使用虚拟环境(使用标准库venv创建)时遇到了以下问题:

  • PyCharm无法自动激活虚拟环境。
  • 在手动激活后(可以按照这个线程的方法进行),一些Bash命令(如git/rm)消失了:

    $ git status
    On branch ...
    Your branch is up to date with '.../...'.
    nothing to commit, working tree clean
    $ . venv/Scripts/activate
    (venv) $ git status
    bash: git: command not found
    

即使在取消激活后

(venv) $ deactivate
$ git status
bash: git: command not found

它们也无法访问。

0
0 Comments

在PyCharm Git-Bash控制台上手动激活虚拟环境后,出现了“Bash commands missing (bash: command not found)”的问题。解决方法是通过在“文件”->“设置”->“工具”->“终端”菜单中禁用“激活虚拟环境”选项,保存更改后重新打开终端即可。

原因是在手动激活虚拟环境后,可能会导致一些Bash命令无法找到。禁用“激活虚拟环境”选项可以避免这个问题。以下是解决方法的具体步骤:

1. 打开PyCharm,点击顶部菜单中的“文件”选项。

2. 在下拉菜单中选择“设置”。

3. 在设置窗口中,找到左侧菜单中的“工具”选项。

4. 在工具选项下找到“终端”选项。

5. 在终端选项中,找到“激活虚拟环境”复选框。

6. 取消勾选“激活虚拟环境”复选框。

7. 点击右下角的“应用”按钮,保存更改。

8. 关闭终端窗口。

9. 重新打开终端窗口。

通过以上步骤,可以解决“Bash commands missing (bash: command not found)”的问题。在禁用“激活虚拟环境”选项后,重新打开终端窗口后,可以正常使用Bash命令。

以下是一个示例,展示了禁用“激活虚拟环境”选项后的终端输出:

$ . venv/Scripts/activate
(venv) $ git status
On branch ...
Your branch is up to date with '.../...'.
nothing to commit, working tree clean

0