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
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 6,728 Dec-16-2025, 05:29 PM
Last Post: zodazy
  Web project and running a .py file emont 0 1,575 Dec-11-2022, 11:15 PM
Last Post: emont
  python run all py files from main py file mg24 6 4,787 Oct-12-2022, 04:41 AM
Last Post: mg24
  help with project of reading and searching big log file korenron 6 4,135 Jun-24-2021, 01:57 PM
Last Post: korenron
  Calling main in project structure fails sandro4912 0 2,312 Aug-22-2020, 01:51 PM
Last Post: sandro4912
  how to run another function from main file Mekala 3 6,152 Aug-09-2020, 04:41 AM
Last Post: deanhystad
  How to build exe/deployable file from Python Project ShikhaJain 1 3,865 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 4,613 Jan-01-2019, 04:19 PM
Last Post: AykutRobotics
  Compile python project to single portable .exe file Campbell 5 14,025 Dec-05-2017, 01:20 PM
Last Post: buran
  How to transfer a music file, from "uploads" directory into my project sylas 15 13,197 Sep-10-2017, 09:16 PM
Last Post: sylas

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.