{"id":4450,"date":"2020-08-20T16:26:18","date_gmt":"2020-08-20T10:56:18","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=4450"},"modified":"2022-09-11T13:42:12","modified_gmt":"2022-09-11T08:12:12","slug":"how-to-install-nltk-on-windows-mac-or-linux","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/how-to-install-nltk-on-windows-mac-or-linux\/","title":{"rendered":"How to Install NLTK on Windows, Mac or Linux"},"content":{"rendered":"\n<p>To get started with <a href=\"https:\/\/www.h2kinfosys.com\/blog\/understanding-nltk-in-python-tutorial\/\">NLTK<\/a>, you will need to get the library up and running on your machine. In this tutorial, you will learn<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>How to install NLTK in Windows<\/li><li>How to install python in Windows&nbsp;<\/li><li>How to install NLTK in Mac or Linux<\/li><li>How to install NLTK from Anaconda<\/li><li>How to download NLTK dataset<\/li><li>How to download all NLTK packages<\/li><li>How to run NLP script<\/li><li>How to run NLTK script<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Install NLTK in Windows<\/strong><\/h2>\n\n\n\n<p>You will first need to have Python on your machine. So we will start by installing Python. If you have Python already installed on your machine, you can skip this step.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Install Python in Windows<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>Go to the python official website and navigate to the download menu. You can easily do this by click on this link <a href=\"https:\/\/www.python.org\/downloads\/\" rel=\"nofollow noopener\" target=\"_blank\">https:\/\/www.python.org\/downloads\/<\/a><\/li><li>Select the Python version you wish to download. You may want to download the latest version to access the updated packages<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/p7EsAtXldSOrRsAHmPcSiatacGkLoXGM4-S_aHlJkEunz9PeUNs8LkCwcIPdJ0Wd4T_kPAe7WcLmpacozADPVG426zpwFZ-uiwGc7iFPWH9xBiRNLxA2J6TixC1PcGhThbGPsZA3QE2w-AC4NQ\" alt=\"\" title=\"\"><\/figure>\n<\/div>\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/docs.google.com\/drawings\/u\/0\/d\/sGGklw0l4VzWeqy6TGSdr0Q\/image?w=113&amp;h=5&amp;rev=1&amp;ac=1&amp;parent=1ewsNbSGdzrqUKf7Zq5bQUXVRychznZByk8X75Hov_h8\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p>You can access other versions from the listed python releases by version number<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/i3hzeRZ7q5LKUt2e7DGb-gcwWtKJn1gYxQS6I9HbKWXnPpTGCqjHGQ0Z1RZ68aLWaE4pOH9PNo_Eki9cbIZThUOaSVjVY9i57MNZDLhahl27kwrSlxG_MFhWGJUDnI45OhXcKuKqBRUOW5Xpdg\" alt=\"\" title=\"\"><\/figure>\n<\/div>\n\n\n<ol class=\"wp-block-list\" start=\"3\"><li>Once you click on the download button, the download commences&nbsp;<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/91HmI9sgtJEvTH91bUVGstlVX4SilaxyfCKntbeDVL2TNUGRywpJJEPt85ogG7unVBCU6vCywc9PCMYAJmOQ3LLjmJCrI1xwHvyTsbPU2g-ivck1VmLOitpqAdrqZoDphxBo4aI0PBa2OCoO3w\" alt=\"\" title=\"\"><\/figure>\n<\/div>\n\n\n<ol class=\"wp-block-list\" start=\"4\"><li>Once the download is complete, open the downloaded file to begin the installation process. Click on install now<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/SMcqHnlMyuYcseAd4rF_t8fm-hsscXtpZwvRMgkYldvVniTnjlaC7Cc4CaOLH4Zci-Q17Q60yTBMCA2tXBPmK-rC19QHthEAOIaXzDKpIt3nve8nQnT46vI9c6dCil6dctdnlnZ04DwpnmDKGg\" alt=\"\" title=\"\"><\/figure>\n<\/div>\n\n\n<ol class=\"wp-block-list\" start=\"5\"><li>Click on Next till the installation completes.&nbsp;<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/SdHIvx0jcg4Eakeo_w2mfgPxteCqGrnbZySL6lrYt15zB68gaEVGgk9d8rdH06QUCMEM2Z5b0ChRvBy3H_pXXbB66d_xdEAmwOsmOSrySkokqZ9510_yqYPjm74HFXidPMaxCkgYAQ-LoKsjig\" alt=\"\" title=\"\"><\/figure>\n<\/div>\n\n\n<ol class=\"wp-block-list\" start=\"6\"><li>Navigate to the Scripts folder in Python and copy the file path<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/aFVBVpvUXhFbZZEEbDYTHPT4WdAWcY0Wc3vKS5sPsyEJJR00uPAPSoGU5-BfoCVhHXm0gMHu22rxfsYQTrhcM4Lp-gdJGhhCohVQHdSfJSwh3JerkS_KrJ2_gPU6N00MLUDUezcNETvTWSjtHw\" alt=\"\" title=\"\"><\/figure>\n<\/div>\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/docs.google.com\/drawings\/u\/0\/d\/sDc0X5pm3Fvycf9LGs9pwoA\/image?w=113&amp;h=5&amp;rev=1&amp;ac=1&amp;parent=1ewsNbSGdzrqUKf7Zq5bQUXVRychznZByk8X75Hov_h8\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"7\"><li>Open command prompt, paste the path there and run this code and wait for the installation to be complete<\/li><\/ol>\n\n\n\n<p><code>pip3 install nltk<\/code><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/ELSDrGWNOJEAmDHs47mSYtWj-5QpGvkd0j11PE5uqcJGQXtdbRMcWaLh3bzXOUnjY6mD4FMl5pJg30OcYOMxaZaJn80BFtTeWEKePkCed3BbOb4l-J6lhciF_A668pyjR2jvVa5Pu_CtqWtjJw\" alt=\"\" title=\"\"><\/figure>\n<\/div>\n\n\n<ol class=\"wp-block-list\" start=\"8\"><li>You can confirm it successfully installed by opening the Python shell and running this code: <\/li><\/ol>\n\n\n\n<p><code>import nltk.&nbsp;<\/code><\/p>\n\n\n\n<p>If it runs without error, NLTK has been installed successfully on your PC.&nbsp;<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/w2NjQq721JqGAwGfW7iweW4SzdWEXknStmFaCZSCgSfxizRG0zZOBdjwE7cb1GBrnQdUX8yuzUYkbznoNE4hFwfalkYM-ScoUp-aeOumpcyUdBOpBz_8_HKm6gI_aMO00jgzgyA7zgfwecJoUg\" alt=\"\" title=\"\"><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Install NLTK for Mac\/Linux<\/strong><\/h2>\n\n\n\n<p>Unlike in Windows, Python is preinstalled in Linux\/Max systems, although the older machines may have Python 2. But to install NLTK in Linux\/Mac, the same python\u2019s pip installer is used. To do this, open your command prompt and type the commands below.&nbsp;<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>First, it is good practice to update the package index. To do this, type the command&nbsp;<\/li><\/ol>\n\n\n\n<p><code>sudo apt update<\/code><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li>To install another version of Python in a Linux system, type<\/li><\/ol>\n\n\n\n<p><code>sudo apt-get install python3.7<\/code><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\"><li>To install pip for python 3, type in&nbsp;<\/li><\/ol>\n\n\n\n<p><code>sudo apt install python-pip<br>pip install -U pip<br>pip install \u2013upgrade pip<\/code><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\"><li>Once pip is installed, you can now install NLTK using the following command<\/li><\/ol>\n\n\n\n<p><code>sudo pip install -U nltk<br>sudo pip3 install -U nltk<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Install NLTK from Anaconda<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>First, you will need to have Anaconda installed on your system. Visit their website and click on the download menu. You could as well use this link and click on download <a href=\"https:\/\/www.anaconda.com\/products\/individual#download-section\" rel=\"nofollow noopener\" target=\"_blank\">https:\/\/www.anaconda.com\/products\/individual#download-section<\/a><\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/4i0bVAziLmzhCdgfD7qFuCmPOC3vlgv7ZVgXw9hxrtTbkmecaQwYxCMbuCGzhJR7wJR_Oxi18_SaU9fFr6ul8ty40J_mJOHAx8w9ZcLo8ZAW-xLlDt-g-0KF_oVYjyREHaP3YKQ_V6_0k3zHHQ\" alt=\"\" title=\"\"><\/figure>\n<\/div>\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/docs.google.com\/drawings\/u\/0\/d\/s9T1TRJMF42UYYtJY2vZBBw\/image?w=113&amp;h=5&amp;rev=1&amp;ac=1&amp;parent=1ewsNbSGdzrqUKf7Zq5bQUXVRychznZByk8X75Hov_h8\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li>Once you successfully download the file open the .exe file to install it.&nbsp;<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/fBe-dnbMS7cusQadyoDOS9HkFj_kGfklYEobNiu7I6lejJdoUx5LyFyKyw6pSJJ4wn_FcQjTwQhQYRCXE-fkUx3h2roD0J1YCJgURHa-cjEr4_nILZNvGfQ13AijnhYtI9bfOlifVSziiMGmEw\" alt=\"\" title=\"\"><\/figure>\n<\/div>\n\n\n<ol class=\"wp-block-list\" start=\"3\"><li>Once the installation is complete, open Anaconda Prompt and end this command<\/li><\/ol>\n\n\n\n<p><code>conda install -c anaconda nltk<\/code><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\"><li>Accept package updates by typing \u2018yes\u2019 and wait for the package to get downloaded.<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to download NLTK dataset<\/strong><\/h2>\n\n\n\n<p>NLTK module has some datasets that will come in handy when doing your projects. You can call these datasets a corpus. Examples of such corpora include stop words, framenet_v15, large_grammers, and many more. To download these datasets, follow these steps&nbsp;<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>On your Python shell, run this command<\/li><\/ol>\n\n\n\n<p><code>import nltk<\/code><br><code>nltk.download()<\/code><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li>An NLTK Downloader dialog box pops up. Click on the download bottom to download the dataset.&nbsp;<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/coDrtMxaynrNvOwFynTk8IZHaMwrwtIVajbBkHUnCCqOdL75c-QLSkkNt4x6sBcMN9wGzCu-1OtOUr1qw-QrrbIS-vjAY2RvxsVGZloqYRrbEBoHpgP-a9N5CsnPCHZ5jOcrXAzXkjvlc84e-w\" alt=\"\" title=\"\"><\/figure>\n<\/div>\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/docs.google.com\/drawings\/u\/0\/d\/slzbc5V055PXWTzWQTKY1Lg\/image?w=113&amp;h=5&amp;rev=1&amp;ac=1&amp;parent=1ewsNbSGdzrqUKf7Zq5bQUXVRychznZByk8X75Hov_h8\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\"><li>To check it has successfully download, run this command<\/li><\/ol>\n\n\n\n<p class=\"has-text-align-left\"><code>from nltk import corpus<\/code><\/p>\n\n\n\n<p>If it runs without error, it is successfully installed.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Run NLTK Script<\/strong><\/h2>\n\n\n\n<p>There are many modules and functions in the NLTK library. Let\u2019s just run a simple tokenize function on a chunk of text<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from nltk import tokenize\ntext = \"Wow, I am almost done with this tutorial\"\nprint(tokenize.word_tokenize(text))\n\n<strong>Output: <\/strong>['Wow', ',', 'I', 'am', 'almost', 'done', 'with', 'this', 'tutorial']<\/pre>\n\n\n\n<p>Going forward in this tutorial series, we will discuss different operations the NLTK library is capable of doing. In the meantime, congratulations on writing your first NLTK script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To get started with NLTK, you will need to get the library up and running on your machine. In this tutorial, you will learn How to install NLTK in Windows How to install python in Windows&nbsp; How to install NLTK in Mac or Linux How to install NLTK from Anaconda How to download NLTK dataset [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4467,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[498],"tags":[1246,1247,1248,1249],"class_list":["post-4450","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-artificial-intelligence-tutorials","tag-install-nltk-in-windows","tag-install-python","tag-nltk-dataset","tag-nltk-packages"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/4450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=4450"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/4450\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/4467"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=4450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=4450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=4450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}