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'
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.
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.
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.
Figured out whats wrong. In the configuration window in pycharm, I had to select proper script path:
In your Pycharm:
Run - Edit Configurations
Configuration tabs
, select Module name
in option Choose target to run
and type your python file's nameApply
and OK
buttonOr 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With