|
From: Linda C. <ch...@MI...> - 2009-01-24 22:15:06
|
Dear matplotlib-users,
I'm having trouble importing pylab and I hope someone can help me. The error
message is:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Linda>cd desktop\python
C:\Documents and Settings\Linda\Desktop\python>python readdata.py
Traceback (most recent call last):
File "readdata.py", line 1, in <module>
import pylab
File "C:\Python25\Lib\site-packages\pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "C:\Python25\Lib\site-packages\matplotlib\__init__.py", line 127, in
<mod
ule>
import sys, os, tempfile
File "C:\python25\lib\tempfile.py", line 33, in <module>
from random import Random as _Random
ImportError: cannot import name Random
C:\Documents and Settings\Linda\Desktop\python>python
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)]
on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
As you can see, I'm using 2.5. The matploblib module that I downloaded was
from sourceforge.net, as was the python 2.5. readdata.py, the program that
gave this error message, is:
import pylab
with nothing else but comments. The strange thing is this was working
before, and it suddenly stopped working, with the same version and
matplotlib module.
What is the problem?
Thanks,
Linda Chen.
|
|
From: John H. <jd...@gm...> - 2009-01-26 02:37:55
|
On Sat, Jan 24, 2009 at 3:38 PM, Linda Chen <ch...@mi...> wrote: > Dear matplotlib-users, > > I'm having trouble importing pylab and I hope someone can help me. The error > message is: > > > > Microsoft Windows XP [Version 5.1.2600] > (C) Copyright 1985-2001 Microsoft Corp. > > C:\Documents and Settings\Linda>cd desktop\python > > C:\Documents and Settings\Linda\Desktop\python>python readdata.py > Traceback (most recent call last): > File "readdata.py", line 1, in <module> > import pylab > File "C:\Python25\Lib\site-packages\pylab.py", line 1, in <module> > from matplotlib.pylab import * > File "C:\Python25\Lib\site-packages\matplotlib\__init__.py", line 127, in > <mod > ule> > import sys, os, tempfile > File "C:\python25\lib\tempfile.py", line 33, in <module> > from random import Random as _Random > ImportError: cannot import name Random > Any chance there is a directory named "random" in the directory from which you are running python, eg what does "dir" show right before you run python? For example, see http://www.mail-archive.com/num...@sc.../msg14644.html JDH |
|
From: Alan G I. <ala...@gm...> - 2009-01-26 12:58:05
|
On 1/24/2009 4:38 PM Linda Chen apparently wrote: > C:\Documents and Settings\Linda\Desktop\python>python readdata.py > Traceback (most recent call last): > File "readdata.py", line 1, in <module> > import pylab > File "C:\Python25\Lib\site-packages\pylab.py", line 1, in <module> > from matplotlib.pylab import * > File "C:\Python25\Lib\site-packages\matplotlib\__init__.py", line 127, in > <mod > ule> > import sys, os, tempfile > File "C:\python25\lib\tempfile.py", line 33, in <module> > from random import Random as _Random > ImportError: cannot import name Random What happens if you do from random import Random at the interpreter prompt? Alan Isaac |
|
From: Linda C. <ch...@MI...> - 2009-01-26 17:13:20
|
Dear John Hunter,
Thanks for your response. Here is what I get:
C:\Documents and Settings\Linda\Desktop\python>dir
Volume in drive C is WinXP
Volume Serial Number is 543D-51FE
Directory of C:\Documents and Settings\Linda\Desktop\py
01/24/2009 04:34 PM <DIR> .
01/24/2009 04:34 PM <DIR> ..
01/21/2009 10:58 PM 89 data.dat
01/20/2009 02:28 PM 1,001 fileout.py
01/14/2009 04:15 PM 32 first.py
01/24/2009 04:34 PM 130 rand.dat
01/16/2009 03:21 PM 562 random.py
01/21/2009 10:01 PM 818 random.pyc
01/21/2009 02:44 PM 478 random1.py
01/23/2009 04:43 PM 344 readdata.py
01/21/2009 11:29 PM 315 readdata.py~
01/24/2009 04:34 PM 21 readdatatest.py
01/24/2009 04:34 PM 344 readdatatest.py~
01/21/2009 10:58 PM 11 test.dat
12 File(s) 4,145 bytes
2 Dir(s) 17,915,678,720 bytes free
C:\Documents and Settings\Linda\Desktop\python>
Thanks,
Linda.
-----Original Message-----
From: John Hunter [mailto:jd...@gm...]
Sent: Sunday, January 25, 2009 9:38 PM
To: ch...@mi...
Cc: mat...@li...
Subject: Re: [Matplotlib-users] import pylab problem
On Sat, Jan 24, 2009 at 3:38 PM, Linda Chen <ch...@mi...> wrote:
> Dear matplotlib-users,
>
> I'm having trouble importing pylab and I hope someone can help me. The
error
> message is:
>
>
>
> Microsoft Windows XP [Version 5.1.2600]
> (C) Copyright 1985-2001 Microsoft Corp.
>
> C:\Documents and Settings\Linda>cd desktop\python
>
> C:\Documents and Settings\Linda\Desktop\python>python readdata.py
> Traceback (most recent call last):
> File "readdata.py", line 1, in <module>
> import pylab
> File "C:\Python25\Lib\site-packages\pylab.py", line 1, in <module>
> from matplotlib.pylab import *
> File "C:\Python25\Lib\site-packages\matplotlib\__init__.py", line 127, in
> <mod
> ule>
> import sys, os, tempfile
> File "C:\python25\lib\tempfile.py", line 33, in <module>
> from random import Random as _Random
> ImportError: cannot import name Random
>
Any chance there is a directory named "random" in the directory from
which you are running python, eg what does "dir" show right before you
run python? For example, see
http://www.mail-archive.com/num...@sc.../msg14644.html
JDH
|
|
From: John H. <jd...@gm...> - 2009-01-26 17:38:50
|
On Mon, Jan 26, 2009 at 11:12 AM, Linda Chen <ch...@mi...> wrote: > > Dear John Hunter, > > Thanks for your response. Here is what I get: > > C:\Documents and Settings\Linda\Desktop\python>dir > Volume in drive C is WinXP > Volume Serial Number is 543D-51FE > > Directory of C:\Documents and Settings\Linda\Desktop\py > > 01/24/2009 04:34 PM <DIR> . > 01/24/2009 04:34 PM <DIR> .. > 01/21/2009 10:58 PM 89 data.dat > 01/20/2009 02:28 PM 1,001 fileout.py > 01/14/2009 04:15 PM 32 first.py > 01/24/2009 04:34 PM 130 rand.dat > 01/16/2009 03:21 PM 562 random.py > 01/21/2009 10:01 PM 818 random.pyc > 01/21/2009 02:44 PM 478 random1.py > 01/23/2009 04:43 PM 344 readdata.py > 01/21/2009 11:29 PM 315 readdata.py~ > 01/24/2009 04:34 PM 21 readdatatest.py > 01/24/2009 04:34 PM 344 readdatatest.py~ > 01/21/2009 10:58 PM 11 test.dat > 12 File(s) 4,145 bytes > 2 Dir(s) 17,915,678,720 bytes free > > C:\Documents and Settings\Linda\Desktop\python> OK, the problem is that you have a python file called random.py in the folder you are trying to run pylab from. random is a module that is part of the python standard library, and matplotlib depends upon it.. When one of the matplotlib dependencies tries to import random, it sees your random.py file rather than the one that ships with python, because the module search path checks the local dir first. You need to either remove or rename the file, or run pylab from another directory. In general, it is good practice to avoid naming files or modules after one of the python standard library modules. You can find a list here: http://docs.python.org/library/ JDH |