NLTK with flask import error
Question: My folder directory is as such

    
    
    /maindir
      __init__.py
      settings.py
      start
      /run.py
      /venv
        .. other directories for flask here bin,include..etc
      /app
        __init__.py
        main.py
        views.py
        /nbc
          /__init__.py
          naivebayesclassifier.py
    

The naivebayesclassifier.py module uses the nltk library as such

    
    
    from nltk.probability import ELEProbDist, FreqDist
    import nltk
    from collections import defaultdict
    from os import listdir  
    from os.path import isfile, join
    

I'm having an issue where if I try to run the program directly from going into
/app and running

    
    
    python main.py 
    

which further goes on to include nbc and use it, I have no problems.

However when I try to deploy this along with flask. I move one directory out
and run ./start, which has the following

    
    
    . venv/bin.activate
    ./run.py
    

and run.py has the following

    
    
    #!venv/bin/python
    from app import app
    app.run(debug = True)
    

This has worked before I included the nltk library, however now it gives me
the error saying

    
    
    ImportError: No module named nltk.probability
    

I had installed nltk using

    
    
    sudo pip install -U pyyaml nltk
    

but I feel I'm missing some installation somewhere to make it work while
deploying.


Answer: It looks like the activation of your virtualenv is causing the problem. Did
you activate the virtualenv before running `sudo pip install -U pyyaml nltk`?
If not, they were installed globally. Remember that by default, when you
create a virtualenv environment, it will ignore all packages not installed
directly into the environment itself (in other words, it will ignore the
packages you installed globally using `apt-get install`). So, you have two
options:

  1. Install your dependencies into your virtualenv (by activating the virtualenv then doing `pip install nltk`). If nltk depends on any development libraries, you will need to install those development libraries as well. Those can be installed using your package manager (`apt-get`).

  2. Rebuild your virtualenv, this time using the [`--system-site-packages`](http://www.virtualenv.org/en/latest/#the-system-site-packages-option) option. This will allow you to use packages installed outside of the virtualenv environment.

