Question

[Solved] Pycharm gets error “can’t find ‘__main__’ module”

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

C:UsersCostelloPycharmProjectstestvenvScriptspython.exe C:/Users/Costello/PycharmProjects/test
C:UsersCostelloPycharmProjectstestvenvScriptspython.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:UsersCostelloAppDataLocalProgramsPythonPython37python.exe: can't find '__main__' module in 'C:/Users/Costello/PycharmProjects/test'

Solution #1:

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

enter image description here

Solution #2:

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.

Solution #3:

I fixed it by removing values from Interpreter options field in run/debug configurations. While trying to add an interpreter, I had added the python path to the mentioned field.

After clearing out the field all worked well.

You can find run/debug configuration settings in the drop-down left of run icon on top-right of pycharm window.

Respondent: Hori Revens

Solution #4:

Go to “Edit Configuration” and only speciy your filename like filename.py

Existing path —–> C:Usersnp4PycharmProjectsTESTvenv

Try with this —–> C:Usersnp4PycharmProjectsTESTvenvMultiSites.py

Respondent: Aditya Gupta

Solution #5:

I encountered this problem when my cmd was forced to “End Task” by “Task Manager”. My problem solved when I restart my IDE.

Respondent: Nitesh Patil

Solution #6:

“Open ‘Edit Run/Debug configurations’ dialog” (on the top, next to “Run”)
“Edit Configurations”
“script path:” –> select correct script path.

Respondent: Mohsen Hrt

Solution #7:

In Pycharm (Ubuntu):

  1. Create New Project
  2. Give Project Name
  3. Right Click on bin folder
  4. Create New Python File
  5. Write Your Code
  6. Upper Right Side: Add Configuration
  7. Left side: right click on “+” sign
  8. Input full file name
  9. Home/Downloads/myfile.py as “Script path”
  10. python 2.x/3.x as Python Interpreter
  11. Click on apply / ok
Respondent: Togrul

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy