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
#1
Hi all! When I am on the project, I cannot run it. Python says he does not find my "main" file.
Here is my main.py:
if __name__ == '__main__':

    import handling_num
    import factorial
    import case
    import sort
    import chaotic
    import solver
    import roule
    import while_True
    import game_tk
    import game
Reply
#2
Show the error.
Python would not do anything but return as complete, since all you are doing here is importing stuff.
Reply
#3
Error:
E:\Documents>python Py1 C:\Program Files\Python36\python.exe: can't find '__main__' module in 'Py1' E:\Documents>
Strange ! I am on E he goes to C. That may be the reason. But why he does not rest on E ?

I must add that with "python main.py", all the project runs well.
Reply
#4
There is no reason why this should cause an error.
I don't have same packages as you, so used a couple different for import,
but created following python program
dingo.py:
λ cat dingo.py
if __name__ == '__main__':
    import sys
    import tkinter
then ran:
λ python dingo.py
without issue
Reply
#5
#λ cat dingo.py
if __name__ == '__main__':
    import sys
    import tkinter
First line commented or not , file doesn't work. Now error in case first line cmmented:
Error:
E:\Documents\new_files>python f3.py File "f3.py", line 1 λ cat dingo.py ^ SyntaxError: invalid syntax E:\Documents\new_files>python f3.py E:\Documents\new_files>python f3.py E:\Documents\new_files>
Reply
#6
(Mar-04-2018, 07:48 PM)sylas Wrote:
#λ cat dingo.py
if __name__ == '__main__':
    import sys
    import tkinter
First line commented or not , file doesn't work. Now error in case first line cmmented:
Error:
E:\Documents\new_files>python f3.py File "f3.py", line 1 λ cat dingo.py ^ SyntaxError: invalid syntax E:\Documents\new_files>python f3.py E:\Documents\new_files>python f3.py E:\Documents\new_files>
HIs first line is a bash command to output the fie to show you the contents. If you commented that out and get no output that means it worked as nothing is suppose to output from importing usually.

I would suggest to put your project up on github and tell us which file you are running. There is nothing wrong with the interpreter. It is something you are doing.
Recommended Tutorials:
Reply
#7
Notice Py1 is a folder, not a file. Maybe I try something impossible. So in case I have many projects, I cannot tell python "run this project". As for Github, even if I am on Atom, it is very complicated for me to use Github.
Reply
#8
(Mar-04-2018, 09:01 PM)sylas Wrote: Notice Py1 is a folder, not a file.
Python can run a folder if it contains a file __main__.py.
Reply
#9
Error:
E:\Documents>python Py1 C:\Program Files\Python36\python.exe: can't find '__main__' module in 'Py1' E:\Documents>
Reply
#10
Is there a file named "__main__.py" in Py1? don't forget the double underscores on each side of the word 'main'.
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 666 Yesterday, 07:07 AM
Last Post: Bronjer
  Web project and running a .py file emont 0 637 Dec-11-2022, 11:15 PM
Last Post: emont
  python run all py files from main py file mg24 6 1,308 Oct-12-2022, 04:41 AM
Last Post: mg24
  help with project of reading and searching big log file korenron 6 2,165 Jun-24-2021, 01:57 PM
Last Post: korenron
  Calling main in project structure fails sandro4912 0 1,335 Aug-22-2020, 01:51 PM
Last Post: sandro4912
  how to run another function from main file Mekala 3 2,528 Aug-09-2020, 04:41 AM
Last Post: deanhystad
  How to build exe/deployable file from Python Project ShikhaJain 1 2,793 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,922 Jan-01-2019, 04:19 PM
Last Post: AykutRobotics
  Compile python project to single portable .exe file Campbell 5 10,692 Dec-05-2017, 01:20 PM
Last Post: buran
  How to transfer a music file, from "uploads" directory into my project sylas 15 8,761 Sep-10-2017, 09:16 PM
Last Post: sylas

Forum Jump:

User Panel Messages

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