Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not being able to append path to nltk_data #2667

Open
flaviopereirap5 opened this issue Feb 9, 2021 · 1 comment
Open

Not being able to append path to nltk_data #2667

flaviopereirap5 opened this issue Feb 9, 2021 · 1 comment

Comments

@flaviopereirap5
Copy link

flaviopereirap5 commented Feb 9, 2021

print(os.path.join(DATA_DIR, "nltk_data")) nltk.data.path.append(os.path.join(DATA_DIR, "nltk_data")) print(nltk.data.path)

The first print correctly returns the path to the nltk_data folder. Then, I try to append it to the path list, but the print returns the list without the previously appended path.

Also, it is weird, but if I append a wrong path to nltk_data, it correctly appends the wrong path.

I can do it with a previously set environment variable, which is not ideal. And I also cannot do it by setting environment variables programmatically.

@wittyicon29
Copy link

It seems like there might be an issue with how the path is being appended to nltk.data.path. Ensure that the path you're trying to append exists and is in the correct format.

Here's an example of how you can append a path to nltk.data.path:

import nltk
import os

DATA_DIR = "/your/data/directory"

# Join the path and append it to nltk.data.path
new_path = os.path.join(DATA_DIR, "nltk_data")
nltk.data.path.append(new_path)

# Print the updated path list
print(nltk.data.path)

Ensure that the DATA_DIR variable contains the correct directory where your nltk_data folder is located. After appending the path, you should see the updated path list with the newly appended directory.

If the issue persists and the path doesn't appear in the nltk.data.path, there might be a permissions issue or a problem with the path itself. Double-check the permissions of the directory you're trying to append and make sure the Python script has the necessary permissions to access and modify it.

Regarding the behavior where appending a wrong path works, it might be due to how Python's os.path.join function handles the incorrect path. It might create a path that Python recognizes, even if it's incorrect, resulting in successful appending to the nltk.data.path. However, if the path doesn't exist or has issues, it might not behave as expected when used by NLTK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants