Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > The Famous Error Message: "ImportError: No module named python_script"

Reply
Thread Tools

The Famous Error Message: "ImportError: No module named python_script"

 
 
rich murphy
Guest
Posts: n/a
 
      12-14-2006

I am studying Python language. I have Python 2.5 installed in my PC
which is running on Windows XP. I placed the the script called
"python_script" in C:\Python25 directory where all the other Python
files are.

When I tried to import the script called "python_script", it kept
printing the famous error message: "ImportError: No module named
python_script".

I took the file out of "C:\Python25" directory, placed it in
'C:\PythonTests'. The error message kept coming.

The "import" commnand will not work at all.


>>> import python_script


Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named python_script

>>> import sys


>>> sys.path

['', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs',
'C:\\Python25\
\lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\\lib\\lib-tk',
'C:\\Python25
', 'C:\\Python25\\lib\\site-packages']

>>> sys.path

['', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs',
'C:\\Python25\
\lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\\lib\\lib-tk',
'C:\\Python25
', 'C:\\Python25\\lib\\site-packages']

>>> sys.path.append('C:\PythonTests')


>>> sys.path

['', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs',
'C:\\Python25\
\lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\\lib\\lib-tk',
'C:\\Python25
', 'C:\\Python25\\lib\\site-packages', 'C:\\PythonTests']


I uninstall Python2.5, installed Python2.4: the result is the same. The
result is the same with older versions of Python also.

Does anybody know a remedy for this???

 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      12-14-2006
At Wednesday 13/12/2006 22:16, rich murphy wrote:

>I am studying Python language. I have Python 2.5 installed in my PC
>which is running on Windows XP. I placed the the script called
>"python_script" in C:\Python25 directory where all the other Python
>files are.


Verify the file name, should be "python_script.py"

You may want to un-select "Hide extensions for known file types" in
Windows Explorer options.


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ˇgratis!
ˇAbrí tu cuenta ya! - http://correo.yahoo.com.ar
 
Reply With Quote
 
 
 
 
Ben Finney
Guest
Posts: n/a
 
      12-14-2006
"rich murphy" <> writes:

> I am studying Python language.


Welcome! Allow me to direct you to the Python tutorial:

<URL:http://docs.python.org/tut/>

Please take the time to work through all the exercises in that
document, understanding each one before moving on.

I recommend this because:

> I placed the the script called "python_script" in C:\Python25
> directory where all the other Python files are.


you would not make this mistake if you had already worked through the
tutorial.

Enjoy!

--
\ "On the other hand, you have different fingers." -- Steven |
`\ Wright |
_o__) |
Ben Finney

 
Reply With Quote
 
rich murphy
Guest
Posts: n/a
 
      12-14-2006
Thank you both for responding.

Yes of course the file has the ".py" extension and yes I went through
the tutorial.


Gabriel Genellina wrote:
> At Wednesday 13/12/2006 22:16, rich murphy wrote:
>
> >I am studying Python language. I have Python 2.5 installed in my PC
> >which is running on Windows XP. I placed the the script called
> >"python_script" in C:\Python25 directory where all the other Python
> >files are.

>
> Verify the file name, should be "python_script.py"
>
> You may want to un-select "Hide extensions for known file types" in
> Windows Explorer options.
>
>
> --
> Gabriel Genellina
> Softlab SRL
>
> __________________________________________________
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam ˇgratis!
> ˇAbrí tu cuenta ya! - http://correo.yahoo.com.ar


 
Reply With Quote
 
Fredrik Lundh
Guest
Posts: n/a
 
      12-14-2006
rich murphy wrote:

> Thank you both for responding.
>
> Yes of course the file has the ".py" extension and yes I went through
> the tutorial.


since everyone on this forum is importing modules successfully hundreds
of times every day, that's not obvious at all.

try running the interpreter as

python -vv

and see what it prints when you type

import python_script

</F>

 
Reply With Quote
 
rich murphy
Guest
Posts: n/a
 
      12-14-2006

Ben Finney wrote:
> "rich murphy" <> writes:
>
> > I am studying Python language.

>
> Welcome! Allow me to direct you to the Python tutorial:
>
> <URL:http://docs.python.org/tut/>
>
> Please take the time to work through all the exercises in that
> document, understanding each one before moving on.
>
> I recommend this because:
>
> > I placed the the script called "python_script" in C:\Python25
> > directory where all the other Python files are.

>
> you would not make this mistake if you had already worked through the
> tutorial.


The tutorial says: "For instance, use your favorite text editor to
create a file called fibo.py in the current directory with the
following contents:"

So, I assumed "the current directory" is C:\Python25 which did not
work. Then I placed the fibo.py file in C: director. That did not work
either. What directory does it mean then?


>
> Enjoy!
>
> --
> \ "On the other hand, you have different fingers." -- Steven |
> `\ Wright |
> _o__) |
> Ben Finney


 
Reply With Quote
 
Eric Pederson
Guest
Posts: n/a
 
      12-14-2006
rich murphy wrote:

>So, I assumed "the current directory" is C:\Python25 which did not
>work. Then I placed the fibo.py file in C: director. That did not work
>either. What directory does it mean then?
>

OK, forgive me for using 2.4... Can you import "sys"? Assuming you've
got python_script.py at path: "C:\\python_script.py" you might try this
quick test:

>>> import sys
>>> sys.path

['C:\\Python24\\Lib\\idlelib', 'C:\\windows\\system32\\python24.zip',
'C:\\Python24', 'C:\\Python24\\DLLs', 'C:\\Python24\\lib',
'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk',
'C:\\Python24\\lib\\site-packages',
'C:\\Python24\\lib\\site-packages\\win32',
'C:\\Python24\\lib\\site-packages\\win32\\lib'] ## your ouput may be
different
>>> sys.path.append("C:\\")
>>> sys.path

['C:\\Python24\\Lib\\idlelib', 'C:\\windows\\system32\\python24.zip',
'C:\\Python24', 'C:\\Python24\\DLLs', 'C:\\Python24\\lib',
'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk',
'C:\\Python24\\lib\\site-packages',
'C:\\Python24\\lib\\site-packages\\win32',
'C:\\Python24\\lib\\site-packages\\win32\\lib', 'C:\\']
>>> import python_script



6.1.1 The Module Search Path

When a module named spam is imported, the interpreter searches for a
file named spam.py in the current directory [...]

Actually, modules are searched in the list of directories given by the
variable |sys.path| which is initialized from the directory containing
the input script (or the current directory), PYTHONPATH and the
installation-dependent default. This allows Python programs that know
what they're doing to modify or replace the module search path. Note
that because the directory containing the script being run is on the
search path, it is important that the script not have the same name as a
standard module, or Python will attempt to load the script as a module
when that module is imported. This will generally be an error. See
section 6.2 <#standardModules>, ``Standard Modules,'' for more information.


 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      12-14-2006
At Thursday 14/12/2006 03:44, rich murphy wrote:

>The tutorial says: "For instance, use your favorite text editor to
>create a file called fibo.py in the current directory with the
>following contents:"
>
>So, I assumed "the current directory" is C:\Python25 which did not
>work. Then I placed the fibo.py file in C: director. That did not work
>either. What directory does it mean then?


It doesn't matter *which* directory you are, as far as you don't
change it when you enter the interpreter:

C:\TEMP\test\basura>type fibo.py
print "inside",__file__

C:\TEMP\test\basura>python
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import fibo

inside fibo.py
>>>


When it later says "enter the Python interpreter" that means "execute
python from the command line", not PythonWin nor IDLE nor...


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ˇgratis!
ˇAbrí tu cuenta ya! - http://correo.yahoo.com.ar
 
Reply With Quote
 
rich murphy
Guest
Posts: n/a
 
      12-14-2006
Thanks to everyone who responded with valuable suggestions. I
appreciate them all. I found the exact reason why "import" command
fails.

At the beginning I created my script file with MS Notepad. After
studying all the advice, I realized that I did not try other text
editors just becuase the tutorial says: "use your favorite text editor
to create a file called fibo.py in the current directory with the
following contents:"

Then I created another file with the same stuff in it using WordPad.
The behaviour of the "import" command improved a lot but still not
good. Then I used MS-DOS' text editor to create the same file.
Immediately the "import" command worked as it was supposed to. Almost.
"fibo.fib2(100)" command stil does not work.


This is fine:
>>> fibo.fib(1000)

1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987

This not fine:
>>> fibo.fib2(100)

[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]


When I enter "fibo.fib2(100)", I get the following:

>>> fibo.fib2(100)

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Python24\fibo.py", line 11, in fib2
while b < n:
UnboundLocalError: local variable 'b' referenced before assignment


This is fine:
>>> fibo.__name__

'fibo'
>>> fib=fibo.fib
>>> fib(500)

1 1 2 3 5 8 13 21 34 55 89 144 233 377

Both Python2.4 and 2.5 are behaving the same. I will also try to create
the file with Vi editor.

 
Reply With Quote
 
Roel Schroeven
Guest
Posts: n/a
 
      12-14-2006
rich murphy schreef:
> This not fine:
>>>> fibo.fib2(100)

> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
>
>
> When I enter "fibo.fib2(100)", I get the following:
>
>>>> fibo.fib2(100)

> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "C:\Python24\fibo.py", line 11, in fib2
> while b < n:
> UnboundLocalError: local variable 'b' referenced before assignment


Can you show the code of fib2? It looks like there's an error in it, but
without the code it's hard to say anything about it.

> Both Python2.4 and 2.5 are behaving the same. I will also try to create
> the file with Vi editor.


If by Vi you mean Vim, that's my favorite editor for editing Python
code, with Idle second.

--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton

Roel Schroeven
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to install module, No module named scipy_distutils.core (but ihave scipy) process Python 1 10-17-2008 06:19 PM
Using JYTHON inside ANT : access os module -> "ImportError: no module named javaos" eric_bellard Python 1 10-07-2004 05:41 AM
Famous error - Unable to start debugging on the webserver: Details inside loser ASP .Net 3 08-07-2003 08:55 PM
Famous error - Unable to start debugging on the webserver: Details inside loser ASP .Net Web Services 0 08-07-2003 07:56 PM
Famous error - Unable to start debugging on the webserver: Details inside loser ASP .Net Security 0 08-07-2003 07:56 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57