Python version/import confusion
<p>I'm trying to get this Python 2.7 code to work.</p>

<p><a href="https://github.com/slanglab/phrasemachine" rel="nofollow">https://github.com/slanglab/phrasemachine</a></p>

<p>I've downloaded and unzipped the repo from github. Here's what happens when I try to run the code.</p>

<pre><code>phrasemachine$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import phrasemachine
&gt;&gt;&gt; text = "Barack Obama supports expanding social security."  
&gt;&gt;&gt; print phrasemachine.get_phrases(text)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "phrasemachine.py", line 253, in get_phrases
    tagger = TAGGER_NAMES[tagger]()
  File "phrasemachine.py", line 166, in get_stdeng_nltk_tagger
    tagger = NLTKTagger()
  File "phrasemachine.py", line 133, in __init__
    import nltk
</code></pre>

<p>ImportError: No module named nltk</p>

<p>So, I need the nltk module. I have that installed here:</p>

<p>Sure enough, Python 2 doesn't know about nltk.</p>

<pre><code>phrasemachine$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import nltk
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
ImportError: No module named nltk
</code></pre>

<p>But, Python 3 does.</p>

<pre><code>phrasemachine$ python3
Python 3.5.1 (v3.5.1:37a07cee5969, Dec  5 2015, 21:12:44) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import nltk
&gt;&gt;&gt;
</code></pre>

<p>Pip tells me that nltk is already installed, but for 3.5.</p>

<pre><code>$ sudo pip install -U nltk
Requirement already up-to-date: nltk in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nltk-3.2.1-py3.5.egg
</code></pre>

<p>Update 10/10/16: I installed the 2.7 version of Python via brew, which give me the 2.7 pip.</p>

<pre><code>$ /usr/local/bin/pip --version
pip 8.1.2 from /usr/local/lib/python2.7/site-packages (python 2.7)
</code></pre>

<p>Then I installed nltk with that pip:</p>

<pre><code>$ sudo /usr/local/bin/pip install -U nltk
Password:
The directory '/Users/me/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/me/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting nltk
  Downloading nltk-3.2.1.tar.gz (1.1MB)
    100% |ââââââââââââââââââââââââââââââââ| 1.1MB 683kB/s 
Installing collected packages: nltk
  Running setup.py install for nltk ... done
Successfully installed nltk-3.2.1
</code></pre>

<p>It says it installed nltk but the warnings are concerning. And, Python 2.7 still fails to import nltk.</p>

<pre><code>$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import phrasemachine
&gt;&gt;&gt; text = "Barack Obama supports expanding social security." 
&gt;&gt;&gt; print phrasemachine.get_phrases(text)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "phrasemachine.py", line 253, in get_phrases
    tagger = TAGGER_NAMES[tagger]()
  File "phrasemachine.py", line 166, in get_stdeng_nltk_tagger
    tagger = NLTKTagger()
  File "phrasemachine.py", line 133, in __init__
    import nltk
ImportError: No module named nltk
&gt;&gt;&gt; import nltk
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
ImportError: No module named nltk
</code></pre>

<p>Final update! I pointed Python 2.7 to the site packages directory where Homebrew installs stuff and I'm now good!</p>

<pre><code>&gt;&gt;&gt; import sys
&gt;&gt;&gt; sys.path.append('/usr/local/lib/python2.7/site-packages')
</code></pre>

<p>Since you have two python distributions, you also need two versions of <code>pip</code>. Find out where your <code>pip</code> executables are with <code>which -a pip</code>, and install <code>pip</code>  for your Python 2.7 distribution if necessary. Then tell the <code>pip</code> that goes with Python 2.7 (perhaps <code>/usr/local/bin/pip</code>) to install the <code>nltk</code>.</p>

<p>(Edit: Pip must be able to find the proper Python on its PATH. I hadn't thought to go into this.)</p>

python osx python-3.x pip nltk