# IntellIJ IDEA 命令行运行一个 HelloWorld Python 程序

**URL:** <https://www.isharkfly.com/t/intellij-idea-helloworld-python/13367>\
**Category:** Python\
**Tags:** python\
**Created:** [March 7, 2021, 3:40am UTC](https://www.isharkfly.com/t/intellij-idea-helloworld-python/13367 "2021-03-07T03:40:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [March 7, 2021, 3:40am UTC](https://www.isharkfly.com/t/intellij-idea-helloworld-python/13367/1 "2021-03-07T03:40:13Z")

</div>

在 IntelliJ IDEA 中你是可以启用终端的。

启用终端的快捷键为 Alt + F12，或者你也可以使用你的鼠标来选择终端。当终端被选定后， IDEA 将会默认把路径设置到当前项目的根目录下面。

![IDEA](https://www.isharkfly.com/images/transparent.png)

根据我们当前的项目，我们知道我们的 HelloWorld.py 文件在路径 tests/HelloWorld.py 下面。

如果我们希望在终端中测试运行 HelloWorld.py 的话。

你可以在终端工具中输入命令来进行执行。

```auto
python tests/HelloWorld.py

```

如果系统没有提示路径错误的话，那么你将会看到在你的终端中输出程序运行的结果。

当然，你也可以输入 py + 程序的路径来运行，效果和输入 python 是相同的。

```auto
py tests/HelloWorld.py

```

![IDEA-terminal-02](https://www.isharkfly.com/images/transparent.png)

甚至，你还可以直接输入 py，这个时候将会启动进入 Python 的解释环境中。

然后你输入代码

```python
print('hello, world!')

```

你可以看到在你的终端工具中，python 解释器帮你解释了代码并且运行后输出了结果。

![IDEA-terminal-03](https://www.isharkfly.com/images/transparent.png)

简单来说，在 IDEA 的终端工具中，你可以认为 IDEA 帮你启动了一个 CMD 命令行工具，然后你可以在这个命令行工具中执行任何你想要的操作。

其效果与在命令行中执行是一样的。
