0

Disclaimer: I'm new to python and first post, so I apologize if this isn't formatted correctly or somewhere on the site. I haven't found anything thus far though.

I'm using Python 2.7 (32 bit) on Win7 (64 bit) and trying to use matplotlib to generate simple plots. I have numpy, scipy, and installed matplotlib. matplotlib is installed as 32bit.

I have a script ('different.py') that has only one line:

import matplotlib.pyplot as plt

running this script in the command prompt returns the following error:

C:\Users\Robert\Desktop>python different.py
Traceback (most recent call last):
  File "different.py", line 1, in <module>
    import matplotlib as plt
  File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 165, in <module>
    from matplotlib.rcsetup import (defaultParams,
  File "C:\Python27\lib\site-packages\matplotlib\rcsetup.py", line 20, in <module>
    from matplotlib.colors import is_color_like
  File "C:\Python27\lib\site-packages\matplotlib\colors.py", line 54, in <module>
    import matplotlib.cbook as cbook
  File "C:\Python27\lib\site-packages\matplotlib\cbook.py", line 34, in <module>

    import new
  File "C:\Users\Robert\Desktop\new.py", line 1, in <module>
    import matplotlib.pyplot
  File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 23, in <module>
    from matplotlib import _pylab_helpers, interactive
ImportError: cannot import name interactive

However, when i open the python (command line) program, and enter

import matplotlib.pyplot as plt
plt

it runs and returns < module 'matplotlib.pyplot' from 'C:\Python27\lib\sitepackages\matplotlib\pyplot.pyc'>

so as far as I can tell it imports the library from the shell, but it's having an issue in the command prompt, and I have no idea why. The only post I've seen related said it was having trouble importing the name interactive because the user had titled their script as "new". I had that originally, but saved the script as 'different.py' thinking it would fix the issue, which it didn't.

Any idea as to why the ImportError is occuring in the command prompt but not the shell?

user2415349
  • 5
  • 1
  • 5

1 Answers1

2

You still have a file called new.py on your desktop. Somewhere along in the chain of import statements, there is an "import new", which finds your new.py, and everything goes wrong:

File "C:\Python27\lib\site-packages\matplotlib\cbook.py", line 34, in <module>
  import new
File "C:\Users\Robert\Desktop\new.py", line 1, in <module>
  import matplotlib.pyplot

Remove or rename your new.py as well as any corresponding new.pyc that may have been created, and try again, or try again from a different working directory.

svk
  • 5,854
  • 17
  • 22
  • sorry for marking your answer so late. I remember I had changed the .py name, but I didn't know about the .pyc. Once I did that it ran perfectly. – user2415349 Jul 11 '13 at 14:40