Python 2.7.1 NLTK won't import

3,387 views
Skip to first unread message

Bio

unread,
Sep 5, 2011, 9:27:12 AM9/5/11
to nltk-users
Hello, This morning I went to do some work in nltk on my MAC. After
opening terminal I opened python and noticed that my version had gone
from 2.6.1 to 2.7.1. So I tried to import nltk and got the error
message ImportError: No module named nltk . I'm guessing that when I
performed the latest LION OS/X upgrade that Python got upgraded from
2.6.1 to 2.7.1 automatically. Does anybody know how to either get nltk
to import with 2.7.1 or revert my Mac back to 2.6.1? Thanks, George

Correa Denzil

unread,
Sep 5, 2011, 10:47:35 AM9/5/11
to nltk-...@googlegroups.com
Use Enthought Python distribution. Check mail archives.
> --
> You received this message because you are subscribed to the Google Groups "nltk-users" group.
> To post to this group, send email to nltk-...@googlegroups.com.
> To unsubscribe from this group, send email to nltk-users+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nltk-users?hl=en.
>
>

--

--Regards,
Denzil


Richard Careaga

unread,
Sep 5, 2011, 10:48:16 AM9/5/11
to nltk-...@googlegroups.com

>From a command line, try

$ pip install nltk

which should put nltk into your 2.7.1 site-packages directory.  Don't mess with the system default Python.


Bio
September 5, 2011 9:27 AM

Bio

unread,
Sep 5, 2011, 10:58:32 AM9/5/11
to nltk-users
Hi Correa, I remembered your Enthought Python distribution suggestion
from an earlier problem I had so that was the first placed I checked.
Unfortunately I am not an academic and Enthought wants almost $200 per
year for a subscription. I would rather find a cost free solution if I
can. Thanks, George

Bio

unread,
Sep 5, 2011, 11:01:40 AM9/5/11
to nltk-users
Hi Richard, Thanks for your suggestion. I tried:

Last login: Mon Sep 5 10:31:17 on ttys000
george-ortons-macbook-pro:~ georgeorton$ pip install nltk
-bash: pip: command not found
george-ortons-macbook-pro:~ georgeorton$

but as you can see I got the pip: command not found error message. Any
idea on what to try next? Thanks, George

Alexis Dimitriadis

unread,
Sep 5, 2011, 11:12:43 AM9/5/11
to nltk-...@googlegroups.com

Richard Careaga

unread,
Sep 5, 2011, 11:14:17 AM9/5/11
to nltk-...@googlegroups.com
Your Python life will be easier if you install either pip (preferably) or easy_install. You can try the install image at http://nltk.googlecode.com/files/nltk-2.0.1rc1.dmg but I'm not sure it's Lion friendly.



Bio
September 5, 2011 11:01 AM

Hi Richard, Thanks for your suggestion. I tried:

Last login: Mon Sep 5 10:31:17 on ttys000
george-ortons-macbook-pro:~ georgeorton$ pip install nltk
-bash: pip: command not found
george-ortons-macbook-pro:~ georgeorton$

but as you can see I got the pip: command not found error message. Any
idea on what to try next? Thanks, George



Richard Careaga
September 5, 2011 10:48 AM


>From a command line, try

$ pip install nltk

which should put nltk into your 2.7.1 site-packages directory.  Don't mess with the system default Python.

Bio

unread,
Sep 5, 2011, 11:31:50 AM9/5/11
to nltk-users
Hello, Thank you for your responses. I tried using the link Alexis
sent to install pip. Unfortunately it was not successful. Here are my
results:

george-ortons-macbook-pro:~ georgeorton$ sudo easy_install pip
Searching for pip
Reading http://pypi.python.org/simple/pip/
Reading http://www.pip-installer.org
Reading http://pip.openplans.org
Best match: pip 1.0.2
Downloading http://pypi.python.org/packages/source/p/pip/pip-1.0.2.tar.gz#md5=47ec6ff3f6d962696fe08d4c8264ad49
Processing pip-1.0.2.tar.gz
Running pip-1.0.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-
ykqSZg/pip-1.0.2/egg-dist-tmp-XsGGsy
warning: no files found matching '*.html' under directory 'docs'
warning: no previously-included files matching '*.txt' found under
directory 'docs/_build'
no previously-included directories found matching 'docs/_build/
_sources'
Adding pip 1.0.2 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip-2.7 script to /usr/local/bin

Installed /Library/Python/2.7/site-packages/pip-1.0.2-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
george-ortons-macbook-pro:~ georgeorton$ pip install nltk
Downloading/unpacking nltk
Downloading nltk-2.0.1rc1.macosx-10.6-x86_64.tar.gz (1.9Mb): 1.9Mb
downloaded
Running setup.py egg_info for package nltk
Traceback (most recent call last):
File "<string>", line 14, in <module>
IOError: [Errno 2] No such file or directory: '/Users/georgeorton/
build/nltk/setup.py'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File "<string>", line 14, in <module>

IOError: [Errno 2] No such file or directory: '/Users/georgeorton/
build/nltk/setup.py'

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /Users/georgeorton/.pip/pip.log
george-ortons-macbook-pro:~ georgeorton$ python
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)]
on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named nltk



I then tried the nltk install link that Richard sent and while the
install seemed to proceed successfully I was still unable to import
nltk. Here is my terminal output after using the install nltk link and
then trying to import nltk:

>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named nltk
>>>

Any further suggestions would be appreciated. Sincerely, George


Bio

unread,
Sep 5, 2011, 1:00:55 PM9/5/11
to nltk-users
Hello, Here is something that confuses me. When I open Python to use
nltk I use Terminal. When I check my .bash_profile I get:

# Setting PATH for MacPython 2.6
# The orginal version is saved in .bash_profile.pysave
PATH="/usr/bin/:/usr/bin/Library/Frameworks/Python.framework/Versions/
2.6/bin:${PATH}"
export PATH
export PYTHONPATH="/Library/Python/2.6/site-packages:/Library/
Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages"


##
# Your previous /Users/georgeorton/.bash_profile file was backed up
as /Users/georgeorton/.bash_profile.macports-
saved_2010-12-12_at_10:26:50
##

# MacPorts Installer addition on 2010-12-12_at_10:26:50: adding an
appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with
MacPorts.

I was under the impression that if I opened Python from terminal the
version of Python opened was determined by the PYTHONPATH statement in
my .bash_profile. Why is it then that when I open Python from inside
Terminal I am getting Python 2.7.1 rather than 2.6.1. I know that I
did not intentionally upgrade to 2.7.1. Is there something that
supersedes the bash profile when determining which Python version to
open and if so can I change that superseding path to 2.6.1 to default
open Python 2.6.1? Thanks, George

Bio

unread,
Sep 5, 2011, 1:08:02 PM9/5/11
to nltk-users
Hi Correa, I have been looking more closely at the Enthought Python
Distribution. I notice that EDP Free contains Python 2.7.2. I also
notice that none of the Enthought versions list nltk as one of the
available packages. Do you think that if I downloaded the EDP free
package that contains Python 2.7.2 then I would be able to import
nltk? Thanks, George

On Sep 5, 10:47 am, Correa Denzil <mcen...@gmail.com> wrote:

Richard Careaga

unread,
Sep 5, 2011, 1:25:08 PM9/5/11
to nltk-...@googlegroups.com
2.7.1 is the Lion default.



Bio
September 5, 2011 1:00 PM


Bio
September 5, 2011 11:31 AM


Richard Careaga
September 5, 2011 11:14 AM

Your Python life will be easier if you install either pip (preferably) or easy_install. You can try the install image at http://nltk.googlecode.com/files/nltk-2.0.1rc1.dmg but I'm not sure it's Lion friendly.



Bio
September 5, 2011 11:01 AM
Hi Richard, Thanks for your suggestion. I tried:

Last login: Mon Sep 5 10:31:17 on ttys000
george-ortons-macbook-pro:~ georgeorton$ pip install nltk
-bash: pip: command not found
george-ortons-macbook-pro:~ georgeorton$

but as you can see I got the pip: command not found error message. Any
idea on what to try next? Thanks, George

Bio

unread,
Sep 5, 2011, 1:41:58 PM9/5/11
to nltk-users
Hi, If 2.7.1 is the Lion default does that mean that I can't put the
Enthought 2.7.2 version on my MAC. Am I stuck here? Is there no way to
get nltk to work with LION? Sincerely, George

Dan Garrette

unread,
Sep 5, 2011, 2:20:09 PM9/5/11
to nltk-...@googlegroups.com
Can't you just add the path to your nltk source code to your PYTHONPATH?

Bio

unread,
Sep 5, 2011, 2:28:51 PM9/5/11
to nltk-users
Hi Dan, Thank you for your response. That sounds reasonable to me, but
I'm not sure how to do that. Do you know how to go about that?
Sincerely, George

Bio

unread,
Sep 5, 2011, 2:42:41 PM9/5/11
to nltk-users
Hello, While searching the web for a solution to this problem I found
this link:

http://parkerboundy.com/post/3455652319/natural-language-toolkit-on-os-x-10-6-6

In it it described a problem similar to the one I am facing. Here is a
quote about how the author solved the problem:

"Natural Language Toolkit on OS X 10.6.6
I’ve been struggling for the last few hours to get the Natural
Language Toolkit (nltk) running on my mac, so I thought I would do a
quick write up for anyone else who might be having similar problems.
For those who don’t know, the nltk is:
“Open source Python modules, linguistic data and documentation for
research and development in natural language processing and text
analytics, with distributions for Windows, Mac OSX and Linux.”
Macs come with python preinstalled (mine had 2.6.x) on it. One would
think this is a good thing (less work!) but you’d be wrong. After
doing a bit of read, Apple’s python is out of date and many libraries
don’t support it. That means we need to install another version of
Python. This is what caused me the biggest headache and an hour or so
of my time. You need the 32bit version of Python in order to run the
nltk’s dependancies. As of writing this the most current version is
2.7.1 and can be found here.
Once you have installed Python you can install the nltk and its
dependencies. Once I figured out the 64bit problem the rest is quick
and simple. I started by installing PyYAML. Download and unpack the
PyYAML folder, and move it to your desktop. Fire up the Terminal
(Applications > Utilities > Terminal) and use the following commands:

cd Desktop/PyYAML-3.09
sudo python setup.py install
No big deal. Now we need to install NumPy and MatPlotLib. They both
have binaries that can be downloaded and are quick and easy to install
(as long as you have the 32 bit version of Python :P).
The last step is to install the nltk. The latest version can be found
here. The nltk also comes in a binary form for OS X, but for some
reason it doesn’t install in the proper location (it wants to install
in Apple’s python location, not the location of our new install). To
fix this, we need to use the terminal and run the following commands:

cd /tmp/nltk-installer
sudo python setup.py install
"
I followed the instructions given, downloaded and installed PyYAML
then I tried changing directories to the
cd /tmp/nltk-installer
then typed sudo python setup.py install

After doing this I was able to get nltk to import. It appears that the
big issue is that nltk doesn't want to install in the proper location.
As the author of the link says it wants to install in Apple's python
location but not in the location of the new install. However I have
two systems that are on LION using 2.7.1. On my MacBook Pro I followed
the directions as outlined and was able to import nltk without
difficulty. However, on my Mac Pro I was able to install PyYAML
without difficulty but when I tried to change directories to the /tmp/
nltk-installer directory I got the error message No such file or
directory.

So now my question becomes does anybody know how to find out what the
directory location is of the nltk install so that I can change to the
correct directory prior to executing the sudo python setup.py install
command. Hopefully if I can get the correct install directory then I
should be able to import nltk. Sincerely, George

Dan Garrette

unread,
Sep 5, 2011, 9:05:40 PM9/5/11
to nltk-...@googlegroups.com
Run the following, or, better yet, put it in your ~/.bash_profile

export PYTHONPATH=$PYTHONPATH:<path to the nltk code>

The <path> there should be a folder that contains a folder called 'nltk' and that folder should contain the nltk source folders like 'parse', 'model', 'sem', and lots more stuff.

-Dan

Mat Bettinson

unread,
Sep 5, 2011, 9:21:11 PM9/5/11
to nltk-...@googlegroups.com
On 6 September 2011 00:58, Bio <Sel...@bioasys.net> wrote:

Unfortunately I am not an academic and Enthought wants almost $200 per
year for a subscription. I would rather find a cost free solution if I
can. Thanks, George

There's an Enthought EPD Free now, added quite recently.


It's worth noting that the EPD install actually provides a working easy_install out of the box, and the lovely iPython console.

--
Regards,

Mat Bettinson


Correa Denzil

unread,
Sep 6, 2011, 6:44:56 AM9/6/11
to nltk-...@googlegroups.com
Pretty much. Also to note, you should always use the easy_install shipped with EPD which may be a different version than the one you may have installed separately.
> --
> You received this message because you are subscribed to the Google Groups "nltk-users" group.
> To post to this group, send email to nltk-...@googlegroups.com.
> To unsubscribe from this group, send email to nltk-users+...@googlegroups.com <nltk-users%2Bunsu...@googlegroups.com>.

Bio

unread,
Sep 7, 2011, 10:58:26 AM9/7/11
to nltk-users
Hello, I just wanted to update this thread to let you know that I
installed the Enthought Python Distribution per Denzil's
recommendation. The install proceeded smoothly. I was then able to
install and import nltk without difficulty. Matplotlib also imported
without difficulty. I admit to having been reluctant to install a
different version (2.7.2) of Python on my Mac. However this reluctance
proved to be unwarranted. I would like nto thank everybody for the
help they provided me in addressing my problem, your assistance was
greatly appreciated. Sincerely, George
Reply all
Reply to author
Forward
0 new messages