How to run standalone files in PyCharm

2020-05-31 12:16发布

问题:

I'm doing small time project development using PyCharm. I use Pycharm for its intellisense features. 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. 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.

I will appreciate if someone can provide a workaround for this. I'm using Python 273

回答1:

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.



回答2:

I just came across the same problem. It was because it had a class called TestClass in the file. I changed the name of the class and then I was able to run the file as normal.