Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm gets error "can't find '__main__' module"

Tags:

python

pycharm

Whenever I try to run script via Virtualenv in pycharm, i get this error:

C:\Users\Costello\PycharmProjects\test\venv\Scripts\python.exe C:/Users/Costello/PycharmProjects/test C:\Users\Costello\PycharmProjects\test\venv\Scripts\python.exe: can't find '__main__' module in 'C:/Users/Costello/PycharmProjects/test' 

Everything works fine via idle, or vs code. I figure it must be something with a way that I have setup my pycharm but have no idea what.

edit: this happens whatever I run, even simple print function.

edit: even with choosing regular python intepreteur, same happens just in pycharm

C:\Users\Costello\AppData\Local\Programs\Python\Python37\python.exe: can't find '__main__' module in 'C:/Users/Costello/PycharmProjects/test' 
like image 937
Mladen Milosavljevic Avatar asked Aug 26 '18 21:08

Mladen Milosavljevic


People also ask

Can t find'__ main__'module in Python?

There are two main reasons why the python can't find '__main__' module error might occur. The first reason is that you haven't specified the main module in your Python script. The second reason is that your main module is not located in the same directory as your Python script.

How do I run Main in Pycharm?

Choose Run | Run from the main menu or press Alt+Shift+F10 , and then select the desired run/debug configuration. This way, you can run any available run/debug configuration. Choose the desired run/debug configuration from the popup menu that shows all the run/debug configurations existing in the project.

What is script path in Pycharm?

Script path/Module name. Click the list to select a type of target to run. Then, in the corresponding field, specify the path to the Python script or the module name to be executed. Parameters. In this field, specify parameters to be passed to the Python script.


2 Answers

Figured out whats wrong. In the configuration window in pycharm, I had to select proper script path:

enter image description here

like image 99
Mladen Milosavljevic Avatar answered Sep 23 '22 08:09

Mladen Milosavljevic


In your Pycharm:

  1. Select Run - Edit Configurations
  2. In Configuration tabs, select Module name in option Choose target to run and type your python file's name
  3. Click Apply and OK button

Or the simple way is when you run your code for first time (on a new file) just type keyboard Alt+Shift+F10 to run and save the configuration. On the second time (after configuration is saved) just type Alt+F10 to run your code.

like image 41
Hori Revens Avatar answered Sep 24 '22 08:09

Hori Revens