PyCharm如何运行Python脚本



几天前,我在启用CUDA的情况下运行Tensorflow模型时遇到问题,很长一段时间我都无法解决,因为PyCharm显示了完全没有帮助的消息

"处理完成,退出代码为-103740791(0xC0000409(";

然后我启动了VSCode,并在PowerShell中运行了相同的代码,得到了一条漂亮而广泛的错误消息,使我能够在半小时内解决所有问题(在cmd中运行时也是如此(。其他产出也有所不同。因此,这让我假设PyCharm在某种类型的终端中运行脚本,而不是依赖cmd或PowerShell。

有人知道是不是这样吗?

因此,这让我假设PyCharm在某种类型的自己的终端中运行脚本,而不是依赖cmd或PowerShell。

不一定。PyCharm显示自定义错误消息并不意味着它不依赖cmd。下面是一个Python脚本,它模拟PyCharm使用cmd:所做的操作

# So we can launch a process from Python
import subprocess as sp
# Launches a Python process for a specific file
# `stdout=sp.DEVNULL` suppresses the process output
# so that's why there is no detailed error message
child = sp.Popen(["python", "file.py"], stdout=sp.DEVNULL)
# Start the Python process
process = child.communicate()[0]
# Returns the process exit code
# If the process finishes without errors, it'll return 0
# otherwise, it'll return a "random" value
exit_code = process.returncode
# Displays to stdout the completely unhelpful message
print(f"Process finished with exit code {exit_code} ({hex(exit_code)})")

不管怎样,PyCharm是这么说的:

最初,终端模拟器使用默认的系统shell运行,但它支持许多其他shell,如Windows PowerShell、命令提示符cmd.exe、sh、bash、zsh、csh等。

最新更新