Python Forum
Even if my file is "main.py",cannot run my project
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Even if my file is "main.py",cannot run my project
#11
I renamed my main.py to __main__.py, as you can see on the above error message.
Reply
#12
(Mar-05-2018, 06:28 AM)sylas Wrote: I renamed my main.py to __main__.py, as you can see on the above error message.
I can't see that on the error message because the error message says that it cannot find __main__, not that it finds __main__ and is unhappy with it.

Try the following experiment: create a folder foo containing a single file __main__.py with the following code
print('hello world')
Then run
Output:
python foo
in a console. It should print hello world. On my box (linux) it works both with python 3 and python 2.
Reply
#13
 Directory of E:\Documents\foo

05/03/2018  08:19    <DIR>          .
05/03/2018  08:19    <DIR>          ..
05/03/2018  08:20                21 __main__.py
               1 File(s)             21 bytes
               2 Dir(s)  467 952 185 344 bytes free

E:\Documents\foo>python __main__.py
hello world

E:\Documents\foo>

Bravo Gribouillis. Your foo works well.
E:\Documents>python foo
hello world

E:\Documents>
Reply
#14
I made a mistake while renaming on Py1 the famous __main__.py. So my new Py1 works very well with "python Py1". Thanks again to Gribouillis.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Web project and running a .py file emont 0 620 Dec-11-2022, 11:15 PM
Last Post: emont
  python run all py files from main py file mg24 6 1,249 Oct-12-2022, 04:41 AM
Last Post: mg24
  help with project of reading and searching big log file korenron 6 2,123 Jun-24-2021, 01:57 PM
Last Post: korenron
  Calling main in project structure fails sandro4912 0 1,316 Aug-22-2020, 01:51 PM
Last Post: sandro4912
  how to run another function from main file Mekala 3 2,477 Aug-09-2020, 04:41 AM
Last Post: deanhystad
  How to build exe/deployable file from Python Project ShikhaJain 1 2,764 Jul-04-2019, 05:37 PM
Last Post: snippsat
  Use Variables Generated from Functions in different files to use on the main file AykutRobotics 3 2,877 Jan-01-2019, 04:19 PM
Last Post: AykutRobotics
  Compile python project to single portable .exe file Campbell 5 10,613 Dec-05-2017, 01:20 PM
Last Post: buran
  How to transfer a music file, from "uploads" directory into my project sylas 15 8,678 Sep-10-2017, 09:16 PM
Last Post: sylas
  Since PyCharm knows which file is "main", how can I tell it "run this project" sylas 7 7,860 Sep-03-2017, 11:48 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020