We can install NLTK on different OS as follows −
To install NLTK on Windows OS, follow the underneath steps −
pip3 install nltk
Presently, open the PythonShell from Windows Start Menu and type the accompanying command to confirm NLTK's installation −
If you get no error, you have successfully installed NLTK on your Windows OS having Python3.
In order to install NLTK on Mac/Linux OS, write the following command −
sudo pip install -U nltk
In the event that you don't have pip installed on your PC, then, at that point, adhere to the guidance given beneath to initially install pip −
To begin with, update the package index by following utilizing following command −
sudo apt update
Now, type the following command to install pip for python 3 −
sudo apt install python3-pip
To install NLTK through Anaconda, follow the beneath steps −
To start with, to install Anaconda, go to the connection www.anaconda.com/dissemination/#download-area and afterward select the form of Python you really want to install.
Once you have Anaconda on your computer system, go to its command prompt and write the following command −
conda install -c anaconda nltk
You need to review the output and enter ‘yes’. NLTK will be downloaded and installed in your Anaconda package.
Downloading NLTK’s Dataset and Packages
Presently we have NLTK installed on our PCs however to utilize it we really want to download the datasets (corpus>
accessible in it. A portion of the significant datasets accessible are stpwords, guntenberg, framenet_v15, etc.
With the assistance of following commands, we can download all the NLTK datasets −
You will get the following NLTK downloaded window.
Now, click on the download button to download the datasets.
How to run NLTK script?
Following is the model wherein we are executing Porter Stemmer algorithm by utilizing PorterStemmer nltk class. with this model you would have the option to comprehend how to run NLTK script.
To begin with, we really want to import the natural language toolkit(nltk>
Now, import the PorterStemmer class to implement the Porter Stemmer algorithm.
from nltk.stem import PorterStemmer
Next, create an instance of Porter Stemmer class as follows −
word_stemmer = PorterStemmer(>
Now, input the word you want to stem. −