AttributeError: 'module' object has no attribute 'internals'

1,932 views
Skip to first unread message

hhoward

unread,
Aug 17, 2009, 10:23:07 PM8/17/09
to nltk-users
Dear nltk-users,

I just started out with Python and NLTK on the Macintosh (OS 10.5.8).

I installed Mac Python with no problem.

I downloaded and ran the installer for NLTK, which installed it in /
Library/Python/2.5/site-packages. I tried <import nltk> in IDLE and
got the error "ImportError: No module named nltk". I figured it was
some kind of path problem and finally realized that there was a "site-
packages" directory in /Library/Frameworks/Python.framework/Versions/
2.6/lib/python2.6. I dragged the nltk directory into it and tried
<import nltk> again. I got the error "ImportError: No module named
yaml". I had no idea that yaml was part of nltk, but I dragged it
into /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
site-packages and tried <import nltk> again.

This time, I got the error:

Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
import nltk
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/nltk/__init__.py", line 136, in <module>
from downloader import download, download_shell
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/nltk/downloader.py", line 183, in <module>
urllib2 = nltk.internals.import_from_stdlib('urllib2')
AttributeError: 'module' object has no attribute 'internals'

Since I have no idea what this means, I am stuck.

Any help would be greatly appreciated.

Cordially,
Harry

Steven Bird

unread,
Aug 17, 2009, 11:33:09 PM8/17/09
to nltk-...@googlegroups.com
2009/8/18 hhoward <howh...@gmail.com>:

> I just started out with Python and NLTK on the Macintosh (OS 10.5.8).

You probably already had Python 2.5 to start with.

> I installed Mac Python with no problem.

It looks like you probably picked up Python 2.6 at this step.

> I downloaded and ran the installer for NLTK, which installed it in /
> Library/Python/2.5/site-packages.

That's because it would have run python from the command line, and it
must have picked up the officially installed version (see "python
-V").

I recommend that you remove the new MacPython 2.6 installation, and
reinstall NLTK into the 2.5 site-packages directory. (If you use
macports, the latter step is easy, using "sudo port install
py25-nltk".)

-Steven Bird

hhoward

unread,
Aug 18, 2009, 6:59:22 PM8/18/09
to nltk-users
Dear Steven Bird,

Yes, I already had Python 2.5 to start with. I uninstalled 2.6 and
moved NLTK into the 2.5 site-packages directory. I figured out how to
run Idle from the command line and I was able to import NLTK and run a
few demos.

Then I thought I would try the alternative. I had to install the new
version of Xcode Tools in order to install Macports. I installed py25-
nltk, but it had dependencies, which had dependencies, which had
dependencies, etc. After several hours on my slow machine, and one
crash, I finally had it all, plus a new distribution of Python 2.5,
Perl, tcl, tk, etc, etc. I started Idle, but could not import NLTK. I
guess that Idle could not find it in the directory that Macports put
it in (opt/local/lib/Python2.5/site-packages), because if I move it to
the regular 2.5 site-packages directory, I can import it.

So I have had limited success, after working on it for most of the
day. I cannot get all the demos to work, though that will be a subject
of a new topic.

I am starting to dread trying to explain this to students.

Cordially,
Harry

On Aug 17, 10:33 pm, Steven Bird <s...@csse.unimelb.edu.au> wrote:
> 2009/8/18 hhoward <howha...@gmail.com>:
Message has been deleted

Steven Bird

unread,
Aug 18, 2009, 10:34:25 PM8/18/09
to nltk-...@googlegroups.com
2009/8/19 hhoward <howh...@gmail.com>:

> Then I thought I would try the alternative. I had to install the new
> version of Xcode Tools in order to install Macports. I installed py25-
> nltk, but it had dependencies, ...

Right -- using macports for the first time is an ordeal.

> I started Idle, but could not import NLTK.

You probably need to (install then) run "python_select" to specify
which instance of Python is to be used by default.

> So I have had limited success, after working on it for most of the
> day. I cannot get all the demos to work, though that will be a subject
> of a new topic.

They should all work, so if you have problems, please report them
(ideally to the NLTK issue tracker).

> I am starting to dread trying to explain this to students.

Fair enough. Though I'm not sure what else to do to support mac
users, given that we provide a dmg and macports distributions. If
there's any tweaking or rewriting of instructions that would help,
please let us know, or write up what eventually worked and post it to
this list.

Thanks,
-Steven Bird

hhoward

unread,
Aug 19, 2009, 10:40:16 AM8/19/09
to nltk-users
New day, fresh start.

> You probably need to (install then) run "python_select" to specify
> which instance of Python is to be used by default.

Yes, the instructions on how to do so were buried in the Macports
feedback from the downloads. I selected the Macports distribution
(2.5.4) on both machines that I am testing.

I had been opening Idle directly from its bin directory, which was
probably messing up the path I wanted to use. I tried starting it from
the command line, and initially had a problem with X11 not opening on
one machine, but that was resolved by opening it first and then
starting Idle. I could then import NLTK without any problem.

Suddenly, everything works on both machines, and it's only 9:30 am.

Thanx so much for your help. I will post a summary once I have tried
the entire procedure on a fresh machine. I will also start a new topic
on my problem with the demos.

By the way, is it worthwhile to upgrade to Python 2.6?

Cordially,
Harry

On Aug 18, 9:34 pm, Steven Bird <s...@csse.unimelb.edu.au> wrote:
> 2009/8/19 hhoward <howha...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages