2

I am trying to get matplotlib to work under Windows 7 (64-bit) using Python 2.7 and Eclipse with the PyDev plugin . I installed NumPy from http://www.lfd.uci.edu/~gohlke/pythonlibs/.

The problem is when I write the following code in Eclipse:

import matplotlib.pyplot as plt

plt.figure()

I get the following error:

Traceback (most recent call last):
  File "C:\Users\davedove\Documents\eclipseWorkspace\python.graphExample\example.py", line 1, in <module>
    import matplotlib.pyplot as plt
  File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 104, in <module>
    import os, re, shutil, subprocess, sys, warnings
  File "C:\Python27\lib\shutil.py", line 12, in <module>
    import collections
  File "C:\Python27\Lib\site-packages\matplotlib\collections.py", line 12, in <module>
    import numpy as np
  File "C:\Python27\lib\site-packages\numpy\__init__.py", line 147, in <module>
    import add_newdocs
  File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 9, in <module>
    from numpy.lib import add_newdoc
  File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 4, in <module>
    from type_check import *
  File "C:\Python27\lib\site-packages\numpy\lib\type_check.py", line 8, in <module>
    import numpy.core.numeric as _nx
  File "C:\Python27\lib\site-packages\numpy\core\__init__.py", line 40, in <module>
    from numpy.testing import Tester
  File "C:\Python27\lib\site-packages\numpy\testing\__init__.py", line 8, in <module>
    from unittest import TestCase
  File "C:\Python27\lib\unittest\__init__.py", line 58, in <module>
    from .result import TestResult
  File "C:\Python27\lib\unittest\result.py", line 9, in <module>
    from . import util
  File "C:\Python27\lib\unittest\util.py", line 2, in <module>
    from collections import namedtuple, OrderedDict
ImportError: cannot import name namedtuple

Also with NumPy when I write the following code in Eclipse:

import numpy

add(array([-1.2, 1.2]), array([1,3]))

I get the following error:

Traceback (most recent call last):
  File "C:\Users\davedove\Documents\eclipseWorkspace\python.graphExample\example.py", line 1, in <module>
    import numpy
  File "C:\Python27\lib\site-packages\numpy\__init__.py", line 147, in <module>
    import add_newdocs
  File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 9, in <module>
    from numpy.lib import add_newdoc
  File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 4, in <module>
    from type_check import *
  File "C:\Python27\lib\site-packages\numpy\lib\type_check.py", line 8, in <module>
    import numpy.core.numeric as _nx
  File "C:\Python27\lib\site-packages\numpy\core\__init__.py", line 40, in <module>
    from numpy.testing import Tester
  File "C:\Python27\lib\site-packages\numpy\testing\__init__.py", line 8, in <module>
    from unittest import TestCase
  File "C:\Python27\lib\unittest\__init__.py", line 58, in <module>
    from .result import TestResult
  File "C:\Python27\lib\unittest\result.py", line 9, in <module>
    from . import util
  File "C:\Python27\lib\unittest\util.py", line 2, in <module>
    from collections import namedtuple, OrderedDict
  File "C:\Python27\Lib\site-packages\matplotlib\collections.py", line 13, in <module>
    import numpy.ma as ma
  File "C:\Python27\lib\site-packages\numpy\ma\__init__.py", line 44, in <module>
    import core
  File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 73, in <module>
    from numpy import ndarray, amax, amin, iscomplexobj, bool_
ImportError: cannot import name ndarray

From the command line both NumPy & matplotlib both run fine, I have added both matplotlib and NumPy from preferences -> pydev -> interpreter python. What could be the problem? Also what alternative could I use to create graphs using Python?

Chris
  • 44,602
  • 16
  • 137
  • 156
kostas Doe
  • 43
  • 1
  • 9
  • Whilst this is not the answer to your question, it seems that you have written an incorrect NumPy example: using `import numpy; add(...)` will result in a `NameError`. I think it should be `numpy.add(...)`. – Chris Mar 16 '12 at 09:31
  • For future reference, [WinPython](http://code.google.com/p/winpython/) is another way you could have installed NumPy and Matplotlib on Windows 7 64-bit. – Steve Byrnes Feb 18 '13 at 14:14

2 Answers2

2

Works for me. Very probably you have added matplotlib and numpy directories to your PYTHONPATH, such that matplotlib.collections is imported instead of the collections module from the Python standard library. Try remove matplotlib and numpy directories from the PYTHONPATH in the Eclipse > PyDev > Python interpreter settings.

cgohlke
  • 9,142
  • 2
  • 33
  • 36
  • 1
    I think cgohlke answer is correct, but if you still can't find it out, try just removing your interpreter and adding it back and letting it get the paths for you (and choose only from that list the paths that are needed as it should get things properly there). – Fabio Zadrozny Mar 22 '12 at 11:04
  • Thats not helping.. I have no matplotlib nor numpy in me pythonpath, but problem the same. more, namedtuples are not working with pydoc I'm tired or that problems with numpy and matplotlib on every step.. – Pruntoff May 31 '13 at 10:31
  • For me, I think its a problem with collections – Chet Feb 11 '14 at 07:16
0

I was having the same issue, but follow the instructions at the bottom of the page and installed the SciPy SuperPack. Worked like a charm on Mountain Lion:

https://github.com/fonnesbeck/ScipySuperpack

After it installs numpy you can always just ctrl-C out of the other packages

tylcole
  • 169
  • 1
  • 7