Getting Error can't find '__main__' module in 'X'

M

meakaakka

Hey I am newbie in python.I have installed python 2.7.5 correctly.It is working fine but I am having some issues.I have set windows Enviroment variables.
The problem is when I try to save my program in a folder(C:\Users\John\X)it shows that module error but when I save it outside this X folder ( C:\Users\John ) It runs successfully.How to fix it?
 
D

Dave Angel

Hey I am newbie in python.I have installed python 2.7.5 correctly.It is working fine but I am having some issues.I have set windows Enviroment variables.

Please be a lot more specific. Do you have any particular environment
variables you suspect, and if so, what have you set them to?
The problem is when I try to save my program in a folder(C:\Users\John\X)it shows that module error

Then you'd better tell us what program you were using to save it with.
I've never seen that error from emacs or Notepad++, but perhaps you're
doing something else.
but when I save it outside this X folder ( C:\Users\John ) It runs successfully.How to fix it?

Perhaps you'd better start at the beginning. Thanks for telling us
you're using python Version 2.7.5, Now perhaps you mean not that this
error occurs during the save, but instead during running of the program.

So let's try again. Don't try to answer just certain parts of the
below, but instead make your own problem description that's at least as
thorough. By the time you're done, you just might solve the problem
yourself, or you'll have learned something new about the problem. But
at least you'll help us help you.


You have saved some program (what is its name?) (why not include it
here, since it probably only needs about 3 lines, including an import of
some form?) in the directory C:\Users\John\X.

You then run it, from a cmd prompt, as follows:

C:\Users\John\X > python myprog.py

and you get the following error.

(You fill this in. It's a group of lines called a traceback, and the
whole thing can be useful. Don't summarize or retype it, use copy/paste).

You then move the file to directory C:\Users\John\betterplace, do a cd
there, and run it again from that directory. Now it works, no import
errors, and runs to completion.

So what else is in that first directory? Are you referencing X
somewhere in your code? Are you referencing __name__ (which is a
reserved term with very specific meaning)?

Have you tried keeping the program in C:\Users\John\X but running with
a different current directory?

C:\Users\John\testdir > python ..\X\myprog.py

If I had to mount my crystal ball, I'd say you've got some form of
recursive import going on (thus __main__), and that some module or
package has the name X. You might also have more than one copy of some
python source file, or a sys.path that's messed up.

Some general advice for the future: Avoid using any uppercase in file
and directory names for source code. Avoid any single-letter names.
Avoid doing recursive imports, and NEVER import the script itself from
some other file.

One more thing. Before replying, please read this since you're using
googlegroups:

http://wiki.python.org/moin/GoogleGroupsPython.
 
S

Steven D'Aprano

Hey I am newbie in python.I have installed python 2.7.5 correctly.It is
working fine but I am having some issues.I have set windows Enviroment
variables.

Any particular environment variables? Shall we guess which ones?
The problem is when I try to save my program in a
folder(C:\Users\John\X)it shows that module error

Are you saying that you cannot save in that folder? Sounds like a
permission error, or maybe the folder doesn't exist. Have you tried
saving in that folder with another program? Can you see the folder in
Windows Explorer?

Or do you mean you CAN save in that folder, but... something else
happens? What? We could play guessing games all week, but it would be
better if you actually tell us exactly what is happening. You can see
exactly what happens, we can only see what you tell us. Tell us:

* Where is the file saved?

* What file name does it have?

* EXACTLY how you are trying to run the file.

* If you are trying to launch it from the command line, COPY AND PASTE
the EXACT command you are using.

* If you get an error, and it is in the console, COPY AND PASTE the EXACT
error message you get. ALL of it. Don't summarise, don't leave out bits
you think aren't important, don't retype it from memory, and especially
don't assume that because you know what the error is, we will magically
know too.

The error message will probably start with:

Traceback (most recent call last):


and then end with an exception type and error message, like:

NameError: name 'foo' is not defined

IndexError: list index out of range

SyntaxError: invalid syntax


or similar. Copy and paste the entire error message.

Once you have shown us these details, we might be able to help you, or at
least come back to you with more questions.
 
M

meakaakka

I think I am the dumbest guy.I got it.I was running it in a wrong way.
I was running it like python X hello.py and the problem was in C:\Users\John
I should have first gone in C:\Users\John\X then I should run it like python hello.py
Dave Angel,Steven D'Aprano-Thank you for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top