Importing NLTK, Python 2.7.3, Mac OS

515 views
Skip to first unread message

Simone Romeo

unread,
Nov 6, 2012, 3:22:03 PM11/6/12
to nltk-...@googlegroups.com

Hi,
I have got problems with importing NLTK, and I can't really figure out how I can solve them.
I am following the install instruction of http://nltk.org/install.html, and I have downloaded the file setuptools-0.6c11-py2.7.egg.
I think the problem is that I can't install numpy. Does anybody know or understand why?

Checking from the url http://nltk.org/install.html, it says that installing Numpy is optional.
However, if I try to import NLTK, I receive the following error statement:
(...)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/metrics/segmentation.py", line 44, in <module>
    import numpy
ImportError: No module named numpySo, it seems that Numpy must be installed.
The problem is that if I try to install Numpy, I get the following error statement:
(...)
  File "/private/tmp/pip-build/numpy/numpy/core/setup.py", line 696, in get_mathlib_info

    raise RuntimeError("Broken toolchain: cannot link a simple C program")

RuntimeError: Broken toolchain: cannot link a simple C program

----------------------------------------
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build/numpy

I can't really understand what it is going on, and how I could overcome the problem and get NLTK installed. Could someone help?

Napolitano, Diane

unread,
Nov 6, 2012, 3:44:21 PM11/6/12
to nltk-...@googlegroups.com
Hi.  I'm thinking they mean the install of NumPy is optional if you already have it.  It's a very common and popular package, so a lot of people do.  I'm 99% positive you'll need it for NLTK, so I'd install it.  It's very useful in general. :)

But yeah, the NLTK installation instructions should be more clear about that.

Or did I misunderstand you and the problem is not with installing NLTK but with installing NumPy?

- Diane


From: nltk-...@googlegroups.com [nltk-...@googlegroups.com] on behalf of Simone Romeo [mars...@gmail.com]
Sent: Tuesday, November 06, 2012 3:22 PM
To: nltk-...@googlegroups.com
Subject: [nltk-users] Importing NLTK, Python 2.7.3, Mac OS

--
 
 

Matt Berends

unread,
Nov 6, 2012, 4:00:01 PM11/6/12
to nltk-...@googlegroups.com
> --
>
>


The default numpy installation works by compiling the c code it uses
under the hood. Since by default macs do not ship with a c compiler
ready to use, a little bit of additional work is required to install
the software. Two paths you can take are:

(1) Grab XCode and obtain the gcc tools. A short write-up is here:
http://www.tech-recipes.com/rx/726/mac-os-x-install-gcc-compiler/

(2) Use a pre-built binary. Enthought bundles a great catalog of
scientific computing resources for Python in its epd-free product. It
can be found at http://www.enthought.com/products/epd_free.php

If you anticipate installing additional python tools that have
c-extensions, then (1) is probably the way to go. There may be a fee
to enroll in the Apple Developer program, however.

But, if common tools like numpy are the extent of your needs, then (2)
is probably best.

My 2 cents,

Matt

Alexis Dimitriadis

unread,
Nov 6, 2012, 4:38:47 PM11/6/12
to nltk-...@googlegroups.com
Hi.  I'm thinking they mean the install of NumPy is optional if you already have it.  It's a very common and popular package, so a lot of people do.  I'm 99% positive you'll need it for NLTK, so I'd install it.  It's very useful in general. :)

The instructions mean that you don't need it, but evidently they're wrong. Others reported the same problem recently. At some point numpy must have become a required dependency, but the instructions were not updated. Anyway, you need to install it.

Best,

Alexis
--
 
 

Toddy Mladenov

unread,
Nov 6, 2012, 5:16:37 PM11/6/12
to nltk-...@googlegroups.com
In order to install NumPy on Mac you need to have XCode command line tools installed (NumPy requires some build activities AFAIK). Look at the following post how to install the command line tools: http://stackoverflow.com/questions/9329243/xcode-4-4-command-line-tools

Toddy

--
 
 

Steven Bird

unread,
Nov 6, 2012, 6:02:16 PM11/6/12
to nltk-users
Thanks for pointing out this inconsistency. It would be great if we could assume that Numpy is installed. Please try a binary distribution: http://sourceforge.net/projects/numpy/files/NumPy/1.6.2/  If this works, then I'll update the installation instructions.

Simone Romeo

unread,
Nov 7, 2012, 1:28:08 AM11/7/12
to nltk-...@googlegroups.com
Hi you all,

thank you for your answers. I will first clarify my problem again: I cannot install numpy because I get an error statement when I try to do it.

Some of you have pointed out that I could install Numpy through a binary distribution (I am not sure whether I understand the meaning of "binary distribution", I suppose it means that I don't have to use my terminal and the command sudo to install it, or am I wrong?)

I tried both the distribution Steven Bird and Matt Berends pointed out, actually. I installed them both correctly. What would the following step be? I tried to open Python and state - import nltk, but I still get an error message:
(...)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/__init__.py", line 5, in <module>
    import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): no suitable image found.  Did find:
    /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so: no matching architecture in universal wrapper
>>>

What should I do?

Thanks a lot!


Thank you for answering my question.

Mikhail Korobov

unread,
Nov 7, 2012, 2:53:48 AM11/7/12
to nltk-...@googlegroups.com
Hello,

In my opinion this is a bug in NLTK: intructions said numpy is optional and it is not optional; the only module causing troubles is nltk/metrics/segmentation.py and a simple workaround (like this: https://github.com/kmike/nltk/commit/c735af41ba6a606037813c52d856f11c4b950a2b) would make code work. 

Binary distributions are often the easiest way to get a package, but such distributions don't play well with virtualenvs (and may have other issues).

By the way, there is a third way to get numpy: use pypy - it has (incomplete) numpy module built-in :)


среда, 7 ноября 2012 г., 12:28:08 UTC+6 пользователь Simone Romeo написал:

Steven Bird

unread,
Nov 7, 2012, 7:15:11 AM11/7/12
to nltk-users

On 7 November 2012 18:53, Mikhail Korobov <kmi...@gmail.com> wrote:
In my opinion this is a bug in NLTK: intructions said numpy is optional and it is not optional ...

Yes, you're quite right. I've posted release 2.0.4 which fixes the problem, here:

Simone Romeo

unread,
Nov 7, 2012, 8:11:26 AM11/7/12
to nltk-...@googlegroups.com
Hi,

Thank you again. I have downloaded the release, but I really can't understand how I could have nltk installed. It would be excellent, if you could manage to write the steps I should follow, starting from opening the terminal to giving the command import nltk...

Thank you a lot.


( And by the way, I am reading Natural Language Processing with Python for my university course...)

Steven Bird

unread,
Nov 7, 2012, 8:52:03 PM11/7/12
to nltk-users
Simone -- please try following these instructions again, and report any problems:



--
 
 

Simone Romeo

unread,
Nov 9, 2012, 12:34:10 PM11/9/12
to nltk-...@googlegroups.com
It works!!!

Thank you all!!!
Reply all
Reply to author
Forward
0 new messages