Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run standalone files in PyCharm

Tags:

python

pycharm

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

like image 626
VaidAbhishek Avatar asked Nov 09 '12 02:11

VaidAbhishek


People also ask

How do I run an individual Python file in PyCharm?

Any Python file shown in your folder can be run by right/control clicking on it and selecting in the dropdown menu: Run <name of file without . py> Alternately you can click on the top menu item Run, and in the dropdown menu click on Run... and the current file should appear there. You can click on it.

Can I use PyCharm without project?

Run without any previous configuringAny executable script can be run in PyCharm. You don't need to create any run/debug configuration in advance. A temporary run/debug configuration is already created for you.

Can PyCharm run without Python?

You need at least one Python installation to be available on your machine. For a new project, PyCharm creates an isolated virtual environment: venv, pipenv, poetry, or Conda. As you work, you can change it or create new interpreters.


2 Answers

You can simply choose the 'Run' entry in the context menu for the file in the Project view:

enter image description here

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

enter image description here

and provides options for customizing a range of options supplied automatically each time you run.

like image 110
orome Avatar answered Sep 23 '22 19:09

orome


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.

like image 26
Eugene Gill Avatar answered Sep 19 '22 19:09

Eugene Gill