NLTK installation problem–[Errno 11004] getaddrinfo failed (with detailed installation process)

1. Installation steps:

1.win + R, enter cmd to open the terminal:
pip install nltk

run:

After the installation is complete, enter idle to open the Python Shell:

enter:

import nltk

Enter again to reference the toolkit:

nltk.download()

This interface appears when running:

2. An error will be reported at this time and nltk_data needs to be installed

Download address: mirrors/nltk/nltk_data · GitCode

After downloading, unzip it. It is worth noting that we only need the packages in the picture above, and the others can be deleted; rename the packages to nltk_data and save them to the same directory in the Download Directory as in the previous picture.

Why not change the path in the Download Directory in NLTK Downloader, but change the file name and file storage location?

The respondent has tried it in Pycharm, Jupter Notebook, and python shell. The download path and server index will be modified and then restarted to change back.

Check whether it is in the correct position:

nltk.find('.')

Same path as above.

Close the NLTK Downloader that was opened earlier, return to the python shell, and enter:

import nltk
nltk.download()

①After opening the interface, there is download in the lower left corner, select download all, and the bottom layer prompts to start downloading.

② You can also close the NLTK Downloader that pops up and enter in the shell:

from nltk.book import *

If text1-text9 appears, the download is successful.

2.[Errno 11004] getaddrinfo failed

But the answerer failed, and there was a problem that raw.githubusercontent.com could not be accessed:

The most common method on the Internet is to modify hosts, but the respondent has not yet succeeded. The process of modifying hosts is posted below.

1. Modify hosts
(1) Query the IP of raw.githubusercontent.com:

Copy this address to your browser and access:

Unable to access this page is the reason for the failure. . .

Solution: Query the IP of raw.githubusercontent.com and fill it in hosts.

Use this URL to query: What Is My IP Address? Free IP Lookup

It will be slower because it is a foreign website.

Enter raw.githubusercontent.com in the red circle position

After the query interface jumps, pull down, probably in the middle:

Here is the IP we need.

There is also a website: Information about IP/server raw.githubusercontent.com – Webmaster Tools (chinaz.com)

Same as the four IPs above.

(2) Modify hosts

hosts file path: C:\Windows\System32\drivers\etc

Open hosts in Notepad mode and add the found IP in the last line (you can add all four):

Save and exit, and download the package again as mentioned above:

If you are prompted when saving a file that you do not have permission to save it in this location, you can first save it to another saveable location, and then authorize dragging and dropping it to this location. The original hosts can be deleted and stored in this folder in Notepad format. If it still fails, modify the file’s properties – security – editing permissions, specifically Baidu.

2. Modify server index

After modifying the hosts, I still cannot access raw.githubusercontent.com. The respondent searched hundreds of answers. Some said to use a proxy, some said to circumvent the firewall. Finally, I forgot where I looked and changed the server index to http:/ /www.nltk.org/nltk_data/

This website has all the toolkits for NLTK:

Reference all packages to download from here.

As mentioned earlier: (The respondent has tried it in Pycharm, Jupter Notebook, and python shell. The download path and server index will be modified and then restarted to change back.) Each restart will automatically change to the previous index, but it doesn’t matter. Impact: After modifying the index, you can download all files immediately, and NLTK Downloader will not be used again later.

Here, after the respondent modified the server index, click Refresh in the lower right corner. Because everything has been installed, it displays installed. If it is not installed, select all, and download in the lower left corner.

After the installation is complete, close the download window and enter in the shell:

from nltk.book import *

show:

That is success.

It is worth mentioning that the respondent still failed the night before, but after modifying the index the next day, he was able to download it inexplicably.

Installation and downloading is a game of luck –.–

The knowledge points of the article match the official knowledge archives, and you can further learn relevant knowledge. Python introductory skill treeArtificial IntelligenceNatural Language Processing 379,806 people are learning the system