tags:

views:

240

answers:

2

I had a working installation of NLTK (py26-nltk) on my Mac (OS X 10.6.2). Then I installed numpy. Now when I try to import nltk, I get this:

>>> import nltk
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "nltk/__init__.py", line 83, in <module>
    from collocations import *
  File "nltk/collocations.py", line 39, in <module>
    from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures
  File "nltk/metrics/__init__.py", line 14, in <module>
    from scores import *
  File "nltk/metrics/scores.py", line 15, in <module>
    from scipy.stats.stats import betai
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/stats/__init__.py", line 7, in <module>
    from stats import *
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/stats/stats.py", line 203, in <module>
    from morestats import find_repeats #is only reference to scipy.stats
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/stats/morestats.py", line 7, in <module>
    import distributions
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/stats/distributions.py", line 27, in <module>
    import vonmises_cython
  File "numpy.pxd", line 30, in scipy.stats.vonmises_cython (scipy/stats/vonmises_cython.c:2939)
ValueError: numpy.dtype does not appear to be the correct type object

What has gone wrong? How can I fix this?

+1  A: 

It seems to be more of a matter of [version] incompatibility between SciPy and NumPy versions than between NLTK and Numpy.
While SciPy is not required for NLTK, it is an optional import, and will load if available.

A few hypothesis regarding your situation:

Hyp #1

  • you formerly were running under NumPy 1.3 along with a compatible version of SciPy
  • you recently installed NumPy 1.4 but didn't touch SciPy ==> "Old" SciPy is broken.
    Remedy : Install newer SciPy or uninstall it altogether (although you may be using/needing SciPy, without knowing it, depending on the modules of NLTK you use)
    Alternate Remedy: re-install NumPy 1.3 over 1.4.

Hyp #2 (less likely)

  • You never had SciPy and NLTK was happy, working without it.
  • You recently installed NumPy 1.4 (over 1.3) and SciPy (over nothing)
  • For some reason NumPy and SciPy don't play nice together
    Remedy: Uninstall SciPy
mjv
No amount of SciPy diddling did the trick, but installing NumPy 1.3 over 1.4 got the job done. Thanks!
Neil Ashton
A: 

I had the same problem on Python 2.6 on Windows XP and as suggested by mjv, I uninstalled my old SciPy module and installed the latest, at which stage I got the error that the yaml module was missing.

After installing the PyYAML module, the "import nltk" statement didn't give any errors.

Hope this helps anyone else having the same problem.

Atish

Atish