【问题标题】:Cygwin Does Not run .py and .sh File Created in Visual Studio CodeCygwin 不运行在 Visual Studio Code 中创建的 .py 和 .sh 文件
【发布时间】:2021-03-18 21:08:21
【问题描述】:

我在 Visual Studio Code (2019) 中运行 Cygwin 终端,我尝试运行 hello.sh 和 hello.py 文件,但终端中没有打印任何内容。也没有错误信息。我还尝试在 Visual Studio 之外打开 Cygwin 终端,也没有打印出来。

但是,我在 venv 目录中从 Pycharm 创建了相同的文件,并将这些文件复制到了我的 Cygwin 目录中——它工作正常。

hello.py 文件中的代码:

print("hello world")

hello.sh 文件中的代码:

echo hello world

我在上述所有终端中使用相同的命令运行这些文件:

./hello.sh
python hello.py

当我使用从 Pycharm 生成和复制的 hello.py 和 hello.sh 文件时的输出:

hello world

否则从 Cygwin 运行这两个文件时什么也不会发生。

我想知道这是怎么发生的,以及如何生成可以直接在 VS Studio 中工作的 .py 文件和 .sh。

我看到其他线程在运行 .sh 文件时提到“找不到命令”错误。这不是我的情况,因为不会打印出任何错误。

谢谢!

【问题讨论】:

  • VS在哪里寻找要执行的程序?我怀疑它是否知道 Cygwin,并且知道需要运行 bash 或 python 的 cygwin 版本
  • 也许第一步是运行类似diff hello.py pycharm/hello.py的东西
  • @matzeri 您好,我已将 VS 代码配置为使用 Cygwin 作为集成终端。
  • @Bec Zhao - 进展如何?只需检查一下提供的信息是否有帮助。

标签: python shell visual-studio-code terminal cygwin


【解决方案1】:

根据您的描述,我在电脑上测试了这个过程,建议您参考以下:

  1. 请确保“Cygwin终端”下载安装正确。

  2. 在使用此终端执行文件之前,请先到文件所在的父文件夹。

    1)。在VSCode之外的“Cygwin”终端中执行“hello.sh”文件:

    2)。使用“Cygwin”终端在VSCode中执行“hello.sh”文件:

    3)。在VSCode中使用“Cygwin”终端执行“hello.py”文件:

另外,为了在VSCode中使用“Cygwin”终端,我在“settings.json”中使用了如下设置:

"terminal.integrated.shell.windows": "...:/cygwin64/bin/bash.exe",

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-28
    • 2023-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多