Cannot plot graph using nltk!

2,131 views
Skip to first unread message

Raymond

unread,
Jan 23, 2010, 1:59:55 AM1/23/10
to nltk-users
Hi, I am new to nltk, and I found that I cannot do this, which a one
of the few "Getting Started" exercises:
------------------------------------------------------------------------------------------------------------------------------------------------
>>> import nltk
>>> from nltk.book import *
*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908
>>> text4.dispersion_plot(["citizens", "democracy", "freedom", "duties", "America"])
/usr/local/lib/python2.6/site-packages/nltk/draw/__init__.py:16:
UserWarning: nltk.draw package not loaded (please install Tkinter
library).
warnings.warn("nltk.draw package not loaded "
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/site-packages/nltk/text.py", line
451, in dispersion_plot
from nltk.draw import dispersion_plot
ImportError: cannot import name dispersion_plot
>>>
---------------------------------------------------------------------------------------------------------------------------------------------
I've already installed python 2.6.4, matplotlib, numpy and MaltParser
I am using opensuse 10.3 (i586)

Please tell me if you get an idea of this error, Thanks

JAGANADH G

unread,
Jan 23, 2010, 2:07:20 AM1/23/10
to nltk-...@googlegroups.com
UserWarning: nltk.draw package not loaded (please install Tkinter
library).


You have to install Tkinter . That is the problem.

 


--
**********************************
JAGANADH G
http://jaganadhg.freeflux.net/blog

Raymond

unread,
Jan 23, 2010, 3:22:05 AM1/23/10
to nltk-users
I got that too.
The python-tk module
already installed before installing nltk
VERSION 2.5.1-39.8

Steven Bird

unread,
Jan 23, 2010, 3:48:12 AM1/23/10
to nltk-...@googlegroups.com
On 23 January 2010 19:22, Raymond <gunbus...@gmail.com> wrote:
> I got that too.
> The python-tk module
> already installed before installing nltk
> VERSION 2.5.1-39.8

Are you able to start a Python session and do:

>>> import Tkinter
>>> import nltk

If not, then you might have two instances of Python installed on your
system, one with Tkinter, and the other with NLTK.

-Steven Bird

Raymond

unread,
Jan 23, 2010, 3:57:35 AM1/23/10
to nltk-users
Yes, I have 2 version of python in the computer
I think the tk is with 2.4.X python
and 2.6.4 is with nltk
how can I fix that?

On Jan 23, 4:48 pm, Steven Bird <stevenbi...@gmail.com> wrote:

Steven Bird

unread,
Jan 23, 2010, 6:02:13 AM1/23/10
to nltk-...@googlegroups.com
On 23 January 2010 19:57, Raymond <gunbus...@gmail.com> wrote:
> Yes, I have 2 version of python in the computer
> I think the tk is with 2.4.X python
> and 2.6.4 is with nltk
> how can I fix that?

You could install NLTK in the location for 2.4.X, or else fix your
2.6.4 setup. Given that you've installed other Python libraries
(probably for Python 2.6), I recommend the latter option.

Tkinter is part of the standard library in 2.6 so its not necessary to
install it separately, but it depends on the tk library (including a
file "libtk") in one of the standard library locations for your
system. I suspect this might be missing from your setup. You'll need
to use your system's package installation tool to get that.

-Steven

Raymond

unread,
Jan 23, 2010, 10:00:32 AM1/23/10
to nltk-users
Sorry, I am not a expert of doing these thing, how can I do that?

The situation is this:
I use opensuse, which bundled with a python 2.4.X version, I installed
it.
Then I think python 2.6.4 is better, so I installed python 2.6.4
and all the later package I installed, were with python 2.6.4.

Now there is an python-tk missing, and the software management
software showed that it is already installed.
So I think it is asscociated with python 2.4.X.
And I cannot find a place for downloading this tkinter....so I cannot
install it manually too.

On Jan 23, 7:02 pm, Steven Bird <stevenbi...@gmail.com> wrote:

Steven Bird

unread,
Jan 23, 2010, 3:14:57 PM1/23/10
to nltk-...@googlegroups.com
On 24 January 2010 02:00, Raymond <gunbus...@gmail.com> wrote:
> Now there is an python-tk missing, and the software management
> software showed that it is already installed.
> So I think it is asscociated with python 2.4.X.

I can't really advise on openSUSE. If it tells you you already have
python-tk, you need to check which version of python-tk it is. From a
quick web search it looks like you would have to have openSUSE 11.1 or
later in order to get Python 2.6 [1]. If you install everything using
the same package manager you should also get all the dependencies
installed too (including libtk).

[1] http://software.opensuse.org/search?q=python-tk

Raymond

unread,
Jan 24, 2010, 12:56:53 AM1/24/10
to nltk-users
No....I install python 2.6.4 manually... not through the software
management software
I installed python 2.4X through YAST...if I try to uninstall it, it
got lots of dependency thing to deal with
So scary

and by the way, I use opensuse 10.3....and opensuse don't provide
support for 10.3
because novell said they need to move "forward"... I hate them
then of coz they don't provide download of tkinter for 10.3 anymore

On Jan 24, 4:14 am, Steven Bird <stevenbi...@gmail.com> wrote:

Steven Bird

unread,
Jan 24, 2010, 2:06:55 AM1/24/10
to nltk-...@googlegroups.com
On 24 January 2010 16:56, Raymond <gunbus...@gmail.com> wrote:
> No....I install python 2.6.4 manually... not through the software
> management software
> I installed python 2.4X through YAST...if I try to uninstall it, it
> got lots of dependency thing to deal with

Right, you shouldn't try to remove 2.4. Instead, you should try to
install 2.6 using YaST. If you do that, all the dependencies should
be taken care of automatically.

-Steven

Raymond

unread,
Jan 24, 2010, 4:55:42 AM1/24/10
to nltk-users
Problem solved^^
installed tcl, tcl-devel, tk, tk-devel, Tkinter from YAST
then reinstall python from source

now it is ok

On Jan 24, 3:06 pm, Steven Bird <stevenbi...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages