简体   繁体   English

如何在PyCharm中运行独立文件

[英]How to run standalone files in PyCharm

I'm doing small time project development using PyCharm. 我正在使用PyCharm进行小型项目开发。 I use Pycharm for its intellisense features. 我使用Pycharm来实现其intellisense功能。 As I develop each piece of code, I like to run it occasionally to test it. 当我开发每段代码时,我喜欢偶尔运行它来测试它。 All I need at the point of development is to be able to run the file. 我在开发时需要的只是能够运行该文件。 However, when I right click and try to run a standalone file, PyCharm tries to be intelligent and shows me options to run my code with unit-tests and other fancy testing gimmicks. 但是,当我右键单击并尝试运行独立文件时,PyCharm会尝试智能化,并向我展示使用单元测试和其他花哨的测试噱头来运行我的代码的选项。 I don't want to deploy any testing framework at this point. 我不想在此时部署任何测试框架。

All I want is to be able to run any file as it is. 我想要的就是能够按原样运行任何文件。 But somehow, PyCharm is not allowing me to do that for every file. 但不知何故,PyCharm不允许我为每个文件执行此操作。

I will appreciate if someone can provide a workaround for this. 如果有人能为此提供解决方法,我将不胜感激。 I'm using Python 273 我正在使用Python 273

You can simply choose the 'Run' entry in the context menu for the file in the Project view: 您只需在项目视图中的文件的上下文菜单中选择“运行”条目:

在此输入图像描述

This will run the file exactly as if you had entered 这将完全像您输入的那样运行文件

python 蟒蛇

from the command line, in the directory containing the file. 从命令行,在包含该文件的目录中。

The first time you do this an entry is also added to the toolbar, which allows you to run the file with a single click 第一次执行此操作时,还会在工具栏中添加一个条目,只需单击一下即可运行该文件

在此输入图像描述

and provides options for customizing a range of options supplied automatically each time you run. 并提供自定义每次运行时自动提供的一系列选项的选项。

I just came across the same problem. 我刚遇到同样的问题。 It was because it had a class called TestClass in the file. 这是因为它在文件中有一个名为TestClass的类。 I changed the name of the class and then I was able to run the file as normal. 我更改了类的名称,然后我能够正常运行该文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM