Can't import nltk module in Juypter notebook?
Asked Answered
A

3

7

I have tried importing nltk module using notebook (Juypter) but its keep showing the error.

ImportError                               Traceback (most recent call last)
<ipython-input-1-b06499430ee0> in <module>()
----> 1 import nltk

ImportError: No module named nltk.   

I have looked at the various solutions. I am able to import the module with the terminal but not in the notebook.

Arterio answered 19/6, 2016 at 14:59 Comment(7)
Your terminal Python installation and your ipython install are separate. What does import sys; print(sys.path) produce in either? Or sys.executable for that matter.Angelitaangell
Could you import in another environment? e.g. ipython, python shell?Lourielouse
@JimRaynor: Yes I am able to import in the python shell and even ipython while using bash.Arterio
@MartijnPieters: This is the output :['', '/Users/farihanaz/anaconda/envs/py27/lib/python2.7/site-packages', '/Users/farihanaz/anaconda/envs/py27/lib/python2.7/site-packages/setuptools-23.0.0-py2.7.egg', '/Users/farihanaz/anaconda/envs/py27/lib/python2.7/site-packages/IPython/extensions', '/Users/farihanaz/.ipython']Arterio
Anaconda comes bundled with the nltk. Are you sure it's succeeding on the commandline and failing in the Notebook, and not the other way around? Check if /Users/farihanaz/anaconda/envs/py27/lib/python2.7/site-packages/nltk exists. If not, find out where it is (ask the successful python for nltk.__file__).Misleading
@alexis: Yes on the command line its working and even nltk folder is there in the site-packages folder.Arterio
as @MartijnPieters suggested ------ import sys !{sys.executable} -m pip install numpy --------- will workPeckham
N
12

Open a command prompt and write:

pip install nltk

This will install the natural language toolkit, after the installation is complete, open Jupyter Notebook and type:

import nltk
nltk.download()

It will take some time and after some time for the auto-configuration of the Jupyter Notebook. Later, you would be able to use is without any issues. Let me know, if you still face any problem.

Nihil answered 29/6, 2017 at 20:5 Comment(1)
I didn't use nltk.download(), but I was able to import sent_tokenize, word_tokenizeSoloman
S
0

If you have anaconda distribution already installed, nltk comes with it by default.

Saliferous answered 12/8, 2019 at 8:59 Comment(0)
U
0

Update:
I downloaded all the packages in nltk. It worked

I didn't use nltk.download() however it is showing error at SentimentIntensityAnalyzer.

import nltk 
from nltk.sentiment import SentimentIntensityAnalyzer
from tqdm.notebook import tqdm sia = SentimentIntensityAnalyzer()'

Here's is image for reference: Traceback

Unconventionality answered 14/2, 2024 at 7:59 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.