[nltk-users] Unable to import nltk on Mac

1,049 views
Skip to first unread message

Bio

unread,
May 11, 2010, 10:25:35 AM5/11/10
to nltk-users
Hello, I just purchased the book Natural Language Processing with
Python by Steven Bird, Ewan Klein & Edward Loper and am trying to use
it to learn Python / NLTK. However after installing Python, NLTK,
NumPy, and Matplotlib as suggested by the text I am unable to run the
two commands >>> import nltk and >>> nltk.download() to install the
data required by the book. I am using a MacBook Pro running Mac OS X
Ver. 10.6.3 (Snow Leopard) and using the Safari Browser. After
installing Python I am able to access the Python IDLE prompt without
difficulty. When I run the command >>> import nltk I get the following
response:

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

I have read each of the discussions in this forum which address the
difficulty importing NLTK onto Macs but have not really been able to
glean any insight into solving my problem. I did try to check whether
I had two versions of Python on my Mac because one thread indicated
that Python is preloaded onto Snow Leopard and that having two
versions of Python may cause a problem when importing NLTK. When I
look for Python on my Mac Finder I can only find one version, when I
run the found version the idle prompt tells me I have:

Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin

I also note that on the download page of nltk.org it is suggested that
if you have a problem importing nltk to try:

If unable to "import nltk" after installing, do cd /tmp/nltk-
installer; sudo python setup.py install - this issue arises if the
NLTK installer could not locate a suitable version of Python on your
machine, or if you have more than one version installed)

When I try >>> cd /tmp/nltk-installer; sudo python setup.py install

I get the response:

SyntaxError: invalid syntax

One of the discussions also suggested trying

>>> sudo port install py26-nltk

which also returned

SyntaxError: invalid syntax

So at this point I am stuck. I wish to work my way through the Natural
Language Processing with Python text but am unable to get past page 3.
If anyone can help me with this issue I would greatly appreciate it.
Sincerely, George Orton

--
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.

Richard Careaga

unread,
May 11, 2010, 11:13:44 AM5/11/10
to nltk-...@googlegroups.com
OK, you've got two choices. The first choice is to use the default Python that came with OS X:

Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

You give up very little in terms of latest and greatestness and your life will be easier.  This is what I recommend. You should also abandon port in favor of easy_install for everything Python related.

Your other choice is to take care that you install all packages into the 2.6.4 site-packages directory, rather than the 2.6.1 site-packages directory where they probably are now. This requires navigating the maze of twisty little passages all alike and figuring out which Python version is referred to where. If you are not very comfortable on the command line, I can't recommend this.

Which way do you want to go?

James Dennis

unread,
May 11, 2010, 11:13:48 AM5/11/10
to nltk-...@googlegroups.com, nltk-...@googlegroups.com
Even better, learn how to use virtualenv and virtuslenvwrapper and
don't muck up the system in any way.

Bio

unread,
May 11, 2010, 11:36:04 AM5/11/10
to nltk-users
Hello Richard, Thank you for your response. It would seem the choice
is obvious, which is to use the default Python that came with the OS
X. So that begs the question, how do I use the default Python. Right
now I am accessing Python directly from Applications in the Mac Finder
window. I am just clicking on the Idle icon under the Python 2.6
folder. Since I don't see any other version of Python in Finder I'm
not sure how I would access the default Python. Should I just delete
the entire Python 2.6 folder?
I used the >>> import nltk command because that is what is
suggested in the Natural Language Processing with Python text, could
you explain how to use easy_install in place of import? Again, thank
you very much for your help I really appreciate it. Sincerely, George

On May 11, 11:13 am, Richard Careaga <leuc...@gmail.com> wrote:
> OK, you've got two choices. The first choice is to use the default
> Python that came with OS X:
>
> Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
> [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>
> You give up very little in terms of latest and greatestness and your
> life will be easier.  This is what I recommend. You should also abandon
> port in favor of easy_install for everything Python related.
>
> Your other choice is to take care that you install all packages into the
> 2.6.4 site-packages directory, rather than the 2.6.1 site-packages
> directory where they probably are now. This requires navigating the maze
> of twisty little passages all alike and figuring out which Python
> version is referred to where. If you are not very comfortable on the
> command line, I can't recommend this.
>
> Which way do you want to go?
>
>
>
>
>
> Bio wrote:
> > Hello, I just purchased the book Natural Language Processing with
> > Python by Steven Bird, Ewan Klein&  Edward Loper and am trying to use

Bio

unread,
May 11, 2010, 11:38:27 AM5/11/10
to nltk-users
Hello James, Thank you for your response. I am not familiar with
either virtualenv or virtuslenvwrapper. Can you please explain the
virtues of using these and how I would go about learning them. Thanks
again. Sincerely, George

On May 11, 11:13 am, James Dennis <j...@j2labs.net> wrote:
> Even better, learn how to use virtualenv and virtuslenvwrapper and  
> don't muck up the system in any way.
>
> > For more options, visit this group athttp://groups.google.com/group/nltk-users?hl=en

Richard Careaga

unread,
May 11, 2010, 11:42:55 AM5/11/10
to nltk-...@googlegroups.com
I think that will make things easier, but there may be a bit of angst along the way.

Please click on the Terminal application inside the utilities subfolder of Applications in Finder.

At the prompt:

$ ls -l /System/Library/Frameworks/Python.framework/Versions

and copy the output, so we can confirm what your default version is.

Bio

unread,
May 11, 2010, 11:50:38 AM5/11/10
to nltk-users
Hello Richard, Thanks Again for your response. I received this
response:

total 8
drwxr-xr-x 8 root wheel 272 Sep 30 2009 2.3
drwxr-xr-x 11 root wheel 374 Apr 1 23:29 2.5
drwxr-xr-x 11 root wheel 374 Apr 1 23:29 2.6
lrwxr-xr-x 1 root wheel 3 Sep 30 2009 Current -> 2.6
george-ortons-macbook-pro:~ georgeorton$

Sincerely, George

Richard Careaga

unread,
May 11, 2010, 11:54:49 AM5/11/10
to nltk-...@googlegroups.com
Good. You may be closer than I thought.

Still from the terminal, not from IDLE,

$python

Do you still get

Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)
?

Bio

unread,
May 11, 2010, 12:03:02 PM5/11/10
to nltk-users
Hello, Yes I received:

Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Thanks, George

Richard Careaga

unread,
May 11, 2010, 12:21:12 PM5/11/10
to nltk-...@googlegroups.com
Thanks, George. I've got an errand to run and won't be back for a few hours, and then I want to think about how gracefully to get you back to 2.6.1 without messing up your installation. We may need to tinker with your paths, instead.

Bio wrote:
Hello, I received:

Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Thanks, George

On May 11, 11:54 am, Richard Careaga <leuc...@gmail.com> wrote:
  

Bio

unread,
May 11, 2010, 12:29:45 PM5/11/10
to nltk-users
Hi Richard, Thanks again for your assistance I really appreciate it.
At 4pm eastern time I need to start running the database program I
have built on my Mac, it takes about 8 hours to complete. Perhaps we
could continue this correspondence tomorrow? If you can correspond
again before 4pm then that would be great but otherwise I will be
unable to access my Mac again until tomorrow. I look forward to
hearing back from you and again I really appreciate your help.
Sincerely, George

Bio

unread,
May 12, 2010, 9:55:47 AM5/12/10
to nltk-users
Hi Richard, When I paste

import sys
sys.path

into the idle prompt I just get the idle prompt returned without any
response. Sincerely, George

Richard Careaga

unread,
May 12, 2010, 10:10:39 AM5/12/10
to nltk-...@googlegroups.com
Hmm. How about from the terminal?

%python
>>> import sys
>>> sys.path

Bio

unread,
May 12, 2010, 10:14:55 AM5/12/10
to nltk-users
Hi, Here is the result from the terminal:

Last login: Wed May 12 10:12:47 on ttys000
george-ortons-macbook-pro:~ georgeorton$ %python
-bash: fg: %python: no such job
george-ortons-macbook-pro:~ georgeorton$ >>> import sys
-bash: syntax error near unexpected token `>'
george-ortons-macbook-pro:~ georgeorton$ >>> sys.path
-bash: syntax error near unexpected token `>'
george-ortons-macbook-pro:~ georgeorton$


George

On May 11, 12:29 pm, Bio <Sel...@BioASys.net> wrote:

Richard Careaga

unread,
May 12, 2010, 10:50:25 AM5/12/10
to nltk-...@googlegroups.com
George,  I think we may be going down a dangerous path for you because you don't have the rudimentary knowledge needed to do basic configuration. Not a rap on you, we all have to begin somewhere. My suggestion is to pick up one of the many introductions to Mac OS that covers the use of the terminal or even a general book on Unix and get familiar with how to enter commands, invoke programs and find the order in which programs look at directories. Until then, having you work in the terminal, especially when using the superpowers conferred by sudo, risks having to do a fresh install of your OS and even trashing any unbacked up files. I know you're eager to get started with nltk, and when you feel confident of your new skills, please come back.

Bio

unread,
May 12, 2010, 11:08:44 AM5/12/10
to nltk-users
Hi Richard, Thanks again for your help. I am looking forward to
learning nltk but I don't mind putting the prerequisite skills in
place to better allow me to learn Python. During our correspondence I
have been looking at books that explain the Apple Terminal. Do you
think that after learning terminal I would have the necessary skills
to install nltk? Can you recommend a particular Terminal book that you
think is worth investing my time in? Would it be possible to just
delete the current 2.6.4 version of Python from my Mac and if so would
that leave the preinstalled version of Python in place? If so would
that deletion allow for the import of nltk? Thanks again for your
assistance. Sincerely, George
> ...
>
> read more »

Richard Careaga

unread,
May 12, 2010, 12:26:41 PM5/12/10
to nltk-...@googlegroups.com
Hi, George

Yes, once you have the very basics down, I think we'll be able to get you going without too much trouble. I'm afraid I don't have a recommendation for you, by the time I started on Mac I already had over 20 years' of Unix experience, so I never looked.

Bio

unread,
Jun 20, 2010, 11:01:06 AM6/20/10
to nltk-users
Hi Richard, I have spent the last month learning Terminal and Unix. I
purchased the book The Mac OS X Command Line, Unix Under the Hood and
worked my way through it. I feel I now have a fair understanding of
Terminal and the beginnings of an understanding of Unix. I followed
your forum discussion with josep_m with great interest as it seemed to
mirror my own situation. However, as best I could tell that discussion
ended before the import NLTK problem was resolved.
So here is where I am at. If at the bash $ prompt I cd to
my Python prompt:

$ cd /Library/Frameworks/Python.framework/Versions/

My prompt changes to:

george-ortons-macbook-pro:Versions georgeorton$

at which point if I

george-ortons-macbook-pro:Versions georgeorton$ ls -l

then I get returned

total 8
drwxrwxr-x 10 root admin 340 Oct 27 2009 2.6
lrwxr-xr-x 1 root admin 3 May 6 11:26 Current -> 2.6

I have not tried to delete any of my Python versions and I have not
tried to install NLTK into the into the 2.6.4 site-packages
directory. So I am essentially where I was at before but now I have a
better understanding of what it is I am trying to do. I am hoping you
will still be willing to help me install NLTK as I still have a very
strong desire to learn Python and NLTK. Thanks, George

PS. I hope all is well with your wife. I have been with my mother as
she has been in and out of the hospital over the past two months so I
have some sense of the stress you may be experiencing.
> ...
>
> read more »

Richard Careaga

unread,
Jun 20, 2010, 12:18:12 PM6/20/10
to nltk-...@googlegroups.com
Hi, George,

Glad to hear you're ready. I'll try to get back to you this evening (EDT). Thanks for asking. We're doing much better now.

Bio

unread,
Jun 20, 2010, 12:51:21 PM6/20/10
to nltk-users
Thanks Richard, I'll look forward to hearing from you. Sincerely,
George
> ...
>
> read more »

Richard Careaga

unread,
Jun 20, 2010, 9:57:54 PM6/20/10
to nltk-...@googlegroups.com
OK, here's what I hesitated to suggest before you were ok with terminal.

If you get

%/usr/bin/path

Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

then

%echo $PATH
/usr/bin:/usr/local/mysql/bin:/usr/local/bin:/Users/Odysseus/bin:/usr/local/subversion/bin:/usr/local/git/bin:/usr/local/boost_1_43_0:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin

and if /usr/bin is not at the beginning, edit your .bash_profile file in your home directory to put it first, then

%source .bash_profile

Bio

unread,
Jun 21, 2010, 7:07:31 AM6/21/10
to nltk-users
Hi Richard, Thank you for your response. Unfortunately for me I am out
of the loop (heavy work schedule) until Thursday Morning and so won't
be able to work on this issue until then. I will work through your
suggestion then and let you know how it went on Thursday. Thanks again
for all your help. Sincerely, George

On Jun 20, 9:57 pm, Richard Careaga <leuc...@gmail.com> wrote:
> OK, here's what I hesitated to suggest before you were ok with terminal.
>
> If you get
>
> %/usr/bin/path
> Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
> [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>  >>>
>
> then
>
> %echo $PATH
> /usr/bin:/usr/local/mysql/bin:/usr/local/bin:/Users/Odysseus/bin:/usr/local /subversion/bin:/usr/local/git/bin:/usr/local/boost_1_43_0:/usr/bin:/bin:/u sr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin
> ...
>
> read more »

Bio

unread,
Jun 24, 2010, 10:51:49 AM6/24/10
to nltk-users
Hi Richard, I am now able to work on installing NLTK again, at least
until 3:00pm Eastern Time. I'm not sure if it makes a difference but I
am using the BASH shell rather than the tcsh shell. Per your
suggestion at my $ prompt I typed /usr/bin/path and received the
response :

-bash: /usr/bin/path: No such file or directory

So using the following command I switched from the bash shell to the
tcsh shell:

chsh -s /bin/tcsh georgeorton

and received the following response when I typed in /usr/bin/path at
the % prompt:

/usr/bin/path: Command not found.

Since I believe that the point of this is to determine which version
of Python is the default version on my Mac I switched back to the bash
shell (I am more familiar with bash but if it makes a difference I can
switch back to tcsh) and at my $ prompt typed:

ls -l /System/Library/Frameworks/Python.framework/Versions

and received the following response:

total 8
drwxr-xr-x 8 root wheel 272 Sep 30 2009 2.3
drwxr-xr-x 11 root wheel 374 Apr 1 23:29 2.5
drwxr-xr-x 11 root wheel 374 Apr 1 23:29 2.6
lrwxr-xr-x 1 root wheel 3 Sep 30 2009 Current -> 2.6

At my $ prompt I then typed python and received the following
response:

Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>


Which indicates to me that my default version is Python 2.6.4

In your previous communication you indicated that if I determined my
default version to be Python 2.6.1 I should edit my .bash_profile in
my home directory to place /usr/bin at the beginning. Because it
appears that my default version is not 2.6.1 I have not done
this .bash_profile edit. I did however run the command echo $PATH at
my $ prompt and received the following response:

/Library/Frameworks/Python.framework/Versions/2.6/bin:/usr/bin:/bin:/
usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

which again would seem to indicate that my default version is 2.6. So
it would seem that I am back to the original problem of setting my
default version of Python to 2.6.1. So any advice you might have on
how to proceed with reverting my system back to the 2.6.1 version
would be greatly appreciated. Thanks again for all your help.
Sincerely, George

Richard Careaga

unread,
Jun 24, 2010, 1:45:46 PM6/24/10
to nltk-...@googlegroups.com
Sorry for my sloppy message--there is no /usr/bin/path as you saw, only /usr/bin/python. Try that and if you get 2.6.1, adjust your path so that /usr/bin: comes first.

Bio

unread,
Jun 24, 2010, 2:13:40 PM6/24/10
to nltk-users
Hi Richard, Thank you for your response. When I use /usr/bin/python I
do get 2.6.1 (Hooray). I have never edited my .bash_profile before. So
when I pull up my .bash_profile in the pico editor I see:

# Setting PATH for MacPython 2.6
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}"
export PATH


Do I change this to read:

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

or do I put in a colon after /usr/bin and before /Library so that
the .bash_profile reads:

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

Thanks again for all your advice. Sincerely, George
> ...
>
> read more »

Richard Careaga

unread,
Jun 24, 2010, 4:32:19 PM6/24/10
to nltk-...@googlegroups.com
Try:

PATH="/usr/bin/:/usr/bin/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}"

^^^^^^^^^^^^^

Bio wrote:
> PATH="/usr/bin/Library/Frameworks/Python.framework/Versions/2.6/bin:$
> {PATH}"
>

Richard Careaga

unread,
Jun 24, 2010, 4:33:06 PM6/24/10
to nltk-...@googlegroups.com
oh, and then

%source .bashrc_profile

josep_m

unread,
Jun 24, 2010, 7:30:43 PM6/24/10
to nltk-users
Hi George,


>
> # Setting PATH for MacPython 2.6
> # The orginal version is saved in .bash_profile.pysave
> PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}"
> export PATH

This is what I had. This is the path that got added when you installed
python from python.org. You must comment this out or simply delete it
if you are going to use the default python that comes with OS X.

Also, read the thread that I initiated. You must delete the directory
Library/Frameworks/Python.framework and all its subdirectories if you
want to eliminate the python version you downloaded from python.org.
If you don't plan to use it, this will make things simpler.

Josep M.
> > >>>>>> purchased the book The MacOSXCommand Line, Unix Under the Hood and
> > >>>>>>>>> risks having to do a fresh install of yourOSand even trashing any
> > >>>>>>>>> unbacked up files. I know you're eager to get started with nltk, and
> > >>>>>>>>> when you feel confident of your new skills, please come back.
>
> > >>>>>>>>> Bio wrote:
>
> > >>>>>>>>>> Hi, Here is the result from the terminal:
>
> > >>>>>>>>>> Last login: Wed May 12 10:12:47 on ttys000
> > >>>>>>>>>> george-ortons-macbook-pro:~ georgeorton$ %python
> > >>>>>>>>>> -bash: fg: %python: no such job
> > >>>>>>>>>> george-ortons-macbook-pro:~ georgeorton$>>>          import sys
> > >>>>>>>>>> -bash: syntax error near unexpected token `>'
> > >>>>>>>>>> george-ortons-macbook-pro:~ georgeorton$>>>          sys.path
> > >>>>>>>>>> -bash: syntax error near unexpected token `>'
>
> ...
>
> read more »

Bio

unread,
Jun 25, 2010, 10:17:55 AM6/25/10
to nltk-users
Hi Richard, I have edited my .bash_profile so that it now reads:

# 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:$$
export PATH


I then ran:

$ source .bash_profile

In your second message regarding editing the .bash_profile you
indicated I should run:

$ source .bashrc_profile

which returned:

-bash: .bashrc_profile: No such file or directory

I then opened IDLE and at the idle prompt I typed:

import nltk

which returned my original error message:

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

Any thoughts you have on moving forward would be greatly appreciated.
I have also been following the thread you have been having with
josep_m and it seems that josep has deleted the python version he
downloaded from this NLTK website. Unfortunately the process by which
he made that downloaded Python version deletion is unclear to me. It
is also not clear to me if after deleting the downloaded Python
version if Josep has been able to install nltk (Hi Josep, if you are
reading this). So again thanks for all your help. Sincerely, George
> ...
>
> read more »

Bio

unread,
Jun 25, 2010, 10:24:40 AM6/25/10
to nltk-users
Hi Josep M., Thank you for your post. I have been following your
thread but unfortunately I am unclear on the process by which you
managed to delete the version of Python you downloaded from this nltk
site. Could I trouble you to write a step by step process which
deletes the downloaded version of Python? After you deleted the
downloaded Python were you able to get the import nltk command to
work? Sincerely, George
> ...
>
> read more »

Bio

unread,
Jun 25, 2010, 10:32:47 AM6/25/10
to nltk-users
Hi Richard, I mis copied my .bash_profile after I modified it.
My .bash_profile actually reads:

# 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

Sincerely, George
> ...
>
> read more »

Richard Careaga

unread,
Jun 25, 2010, 12:04:01 PM6/25/10
to nltk-...@googlegroups.com
I don't think you need to worry about MacP. What do you get now when you

$python

Bio

unread,
Jun 25, 2010, 12:11:18 PM6/25/10
to nltk-users
Hi Richard, Thanks again. Here is what I get when I $python:

george-ortons-macbook-pro:~ georgeorton$ python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

I'm afraid I don't understand what you mean by "I don't think you need
to worry about MacP". Sincerely, George
> ...
>
> read more »

Richard Careaga

unread,
Jun 25, 2010, 12:27:53 PM6/25/10
to nltk-...@googlegroups.com
Bingo! You've got 2.6.1 coming up. Leaving 2.6.4 where it is now won't cause any problems, and you may be able to use it by python2.6.4 in the command line if you wish. Now try

>>>import nltk

Bio

unread,
Jun 25, 2010, 12:36:47 PM6/25/10
to nltk-users
Hi Richard, It does seem that 2.6.1 is now my default however I am
still getting the same error message I got when I first tried to
import nltk. Here is what I get when I try to import nltk from the
idle prompt:

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

Any ideas what's wrong? Thanks, George
> ...
>
> read more »

Bio

unread,
Jun 25, 2010, 12:46:14 PM6/25/10
to nltk-users
Hi Richard, I think I see what the problem is, however I don't know
how to resolve it. When I access idle from my applications folder I
can only find Python 2.6. So when I launch idle here is the interface
I get:

Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "copyright", "credits" or "license()" for more information.

****************************************************************
Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface. This connection is not visible on any external
interface and no data is sent to or received from the Internet.
****************************************************************

IDLE 2.6.4
>>>

Which indicates to me that I am not using the idle from 2.6.1 but
rather from 2.6.4. So if I am right how do I access 2.6.1 instead of
2.6.4? Thanks, George
> ...
>
> read more »

Richard Careaga

unread,
Jun 25, 2010, 12:56:12 PM6/25/10
to nltk-...@googlegroups.com
Hi, George. If I knew that I could get my idle working. In the meantime, I'm using the command line. I'll see what I can discover separately. The issue with not finding nltk is that it is installed to the wrong site-packages program. You've got two choices: 1) re-install, which should work, or 2) set the PYTHONPATH variable in .bash_profile, thusly:

export PYTHONPATH="/Library/Python/2.6/site-packages:/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages"

josep_m

unread,
Jun 25, 2010, 1:55:18 PM6/25/10
to nltk-users
Hi George,

On Jun 25, 4:24 pm, Bio <Sel...@BioASys.net> wrote:
> Hi Josep M., Thank you for your post. I have been following your
> thread but unfortunately I am unclear on the process by which you
> managed to delete the version of Python you downloaded from this nltk
> site. Could I trouble you to write a step by step process which
> deletes the downloaded version of Python? After you deleted the
> downloaded Python were you able to get the import nltk command to
> work?   Sincerely, George


Actually, I didn't download python from the nltk site. I downloaded it
from python.org. I simply deleted

/Library/Frameworks/Python.framework/ with all its subdirectories

You simply do this:

$rm -R /Library/Frameworks/Python.framework/

Then I deleted the contents from the .bash_profile:

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


And yes, after doing that I have no problems importing NLTK.

I would have liked to be able to work with python 2.6.5 (not because I
really need any of the new features but simply because I'm stubborn
and I hate being stumped by something so stupid) but since I'm in a
hurry and need to get things done with NLTK, the Apple default
installation of Python will do.


Josep M

Richard Careaga

unread,
Jun 25, 2010, 2:03:03 PM6/25/10
to nltk-...@googlegroups.com
Great. There are other cases where 2.6.4 gets you grief, especially when trying to compile 64-bit code. But I'm glad you're good to go. (BTW: you would get nltk from the nltk.org site?)

Bio

unread,
Jun 25, 2010, 2:03:29 PM6/25/10
to nltk-users
Hi Richard, I got import nltk to work HOORAAY!!. Thank you so much for
your help. I tried re-installing nltk and that still did not allow me
to use python from the idle interface. So I opened terminal and typed
python at the $ prompt to switch to Python and then from the >>>
prompt within terminal I tried and was successful with the import ntlk
command.

Had I chosen to modify my .bash_profile would I have just added:

export
PYTHONPATH="/Library/Python/2.6/site-packages:/Library/Frameworks/
Python.fr amework/Versions/2.6/lib/python2.6/site-packages"

to the file so that it would look like:

# 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.fr amework/Versions/2.6/lib/python2.6/site-packages"

or would it be some other variation on that?


Thanks again for all your help and for your patience in helping me
resolve this issue. Sincerely, George

On Jun 25, 12:56 pm, Richard Careaga <leuc...@gmail.com> wrote:
> Hi, George. If I knew that I could get /my /idle working. In the
> ...
>
> read more »

Bio

unread,
Jun 25, 2010, 2:09:17 PM6/25/10
to nltk-users
Hi Josep, Thank you for the detailed directions. Fortunately I was
able to get the import nltk command to work by using Richards
instructions to modify my .bash_profile file. Just one caveat though
I have to use the idle interface through terminal. So thanks again.
Sincerely, George
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages