Search code examples
pythonpython-3.xnltkpython-module

How to access NLTK with different versions of Python


I started working with the NLTK 3.0 module for Python 2.7. I have recently shifted to Python 3.6. NLTK 3.0 is compatible with both.

When I try to import NLTK using Python 3.6 (in the IDLE integrated development environment), I get the error:

    import nltk
ModuleNotFoundError: No module named 'nltk'

My question: How do I make the NLTK module available to Python 3.6 without re-downloading the module?

I think it might be as easy as changing the locations of the NLTK files, is this correct?


This question is very similar to this off-topic question:

Python: how to get different versions of python to access the same modules?

except that, unlike scitools, NLTK is compatible with both Python 2.7 and Python 3.6.


Solution

  • It is compatible to both, but you still need to install it for your specific python version (I'm having this problem all the time; having packages installed for another python2.x whereas I thought I installed it for python3.x or the other way round). Usually, (if you're running python3.x now), doing something like

    sudo pip3 install nltk
    

    does the trick. By "without re-downloading the module", do you mean the nltk_data folder? I'm not sure, but think that is by default put in your home folder and can be shared between different python versions. And just doing a pip install shouldn't take too long/there's not that much to download I think.