Problems while installing StanfordCoreNLP in OSX: How to set up the environment variables for jupyter/pycharm?
<p>I downloaded and installed the <a href="http://nlp.stanford.edu/software/CRF-NER.shtml" rel="nofollow">StanfordCoreNLP</a> as <a href="https://gist.github.com/alvations/e1df0ba227e542955a8a" rel="nofollow">follows</a>:</p>

<pre><code>$ cd
$ wget http://nlp.stanford.edu/software/stanford-ner-2015-12-09.zip
$ unzip stanford-ner-2015-12-09.zip
$ ls stanford-ner-2015-12-09/
build.xml    LICENSE.txt   ner-gui.bat      ner.sh                 sample.ner.txt     stanford-ner-3.6.0.jar          stanford-ner.jar
classifiers  ner.bat       ner-gui.command  README.txt             sample.txt         stanford-ner-3.6.0-javadoc.jar
lib          NERDemo.java  ner-gui.sh       sample-conll-file.txt  sample-w-time.txt  stanford-ner-3.6.0-sources.jar
$ export STANFORDTOOLSDIR=$HOME
$ export CLASSPATH=$STANFORDTOOLSDIR/stanford-ner-2015-12-09/stanford-ner.jar
$ export STANFORD_MODELS=$STANFORDTOOLSDIR/stanford-ner-2015-12-09/classifiers
</code></pre>

<p>Then let's try if it actually worked:</p>

<pre><code>$ python3
&gt;&gt;&gt;import nltk
&gt;&gt;&gt; nltk.__version__
'3.1'
&gt;&gt;&gt; from nltk.tag import StanfordNERTagger
&gt;&gt;&gt; st = StanfordNERTagger('english.all.3class.distsim.crf.ser.gz')
&gt;&gt;&gt; st.tag('Rami Eid is studying at Stony Brook University in NY'.split())

[('Rami', 'PERSON'), ('Eid', 'PERSON'), ('is', 'O'), ('studying', 'O'), ('at', 'O'), ('Stony', 'ORGANIZATION'), ('Brook', 'ORGANIZATION'), ('University', 'ORGANIZATION'), ('in', 'O'), ('NY', 'O')]
</code></pre>

<p>So, upon here everything works perfect. The problem is when I close the terminal and start working in the jupyter notebook (or pycharm):</p>

<p>In:</p>

<pre><code>from nltk.tag import StanfordNERTagger
st = StanfordNERTagger('english.all.3class.distsim.crf.ser.gz')
st.tag('Rami Eid is studying at Stony Brook University in NY'.split())
</code></pre>

<p>Out:</p>

<pre><code>---------------------------------------------------------------------------
LookupError                               Traceback (most recent call last)
&lt;ipython-input-2-118c7edca797&gt; in &lt;module&gt;()
      1 from nltk.tag import StanfordNERTagger
----&gt; 2 st = StanfordNERTagger('english.all.3class.distsim.crf.ser.gz')
      3 st.tag('Rami Eid is studying at Stony Brook University in NY'.split())

/usr/local/lib/python3.5/site-packages/nltk/tag/stanford.py in __init__(self, *args, **kwargs)
    166 
    167     def __init__(self, *args, **kwargs):
--&gt; 168         super(StanfordNERTagger, self).__init__(*args, **kwargs)
    169 
    170     @property

/usr/local/lib/python3.5/site-packages/nltk/tag/stanford.py in __init__(self, model_filename, path_to_jar, encoding, verbose, java_options)
     51                 self._JAR, path_to_jar,
     52                 searchpath=(), url=_stanford_url,
---&gt; 53                 verbose=verbose)
     54 
     55         self._stanford_model = find_file(model_filename,

/usr/local/lib/python3.5/site-packages/nltk/__init__.py in find_jar(name_pattern, path_to_jar, env_vars, searchpath, url, verbose, is_regex)
    717         searchpath=(), url=None, verbose=True, is_regex=False):
    718     return next(find_jar_iter(name_pattern, path_to_jar, env_vars,
--&gt; 719                          searchpath, url, verbose, is_regex))
    720 
    721 

/usr/local/lib/python3.5/site-packages/nltk/__init__.py in find_jar_iter(name_pattern, path_to_jar, env_vars, searchpath, url, verbose, is_regex)
    712                     (name_pattern, url))
    713         div = '='*75
--&gt; 714         raise LookupError('\n\n%s\n%s\n%s' % (div, msg, div))
    715 
    716 def find_jar(name_pattern, path_to_jar=None, env_vars=(),

LookupError: 

===========================================================================
  NLTK was unable to find stanford-ner.jar! Set the CLASSPATH
  environment variable.

  For more information, on stanford-ner.jar, see:
    &lt;http://nlp.stanford.edu/software&gt;
===========================================================================
</code></pre>

<p><strong>So, my question is how to set the environment variables correctly?</strong>, I also tried to add this to my bash profile:</p>

<pre><code>#StanfordCORENLP
export STANFORDTOOLSDIR=$HOME
export CLASSPATH=$STANFORDTOOLSDIR/stanford-ner-2015-12-09/stanford-ner.jar
export STANFORD_MODELS=$STANFORDTOOLSDIR/stanford-ner-2015-12-09/classifiers
</code></pre>

<p><strong>Update</strong></p>

<p>Based on @alexis answer, this is what I tried:</p>

<pre><code>user@MacBook-Pro:~$ % jupyter notebook /Users/user/Jupyter/Project1/Version1 &amp;
-bash: bg: %: no such job
-bash: bg: jupyter: no such job
-bash: bg: notebook: no such job
-bash: bg: /Users/user/Jupyter/Project1/Version1: no such job
</code></pre>

<p>And this:</p>

<pre><code>user@MacBook-Pro-de-User:~$ sudo mate /etc/launchd.conf
Password:
path::entries: scandir("/Applications/TextMate.app/Contents/Resources/PrivilegedTool"): Not a directory
</code></pre>

<p>Then:</p>

<pre><code>user@MacBook-Pro-de-User:~$ sudo mate /etc/launchd.conf
Password:
path::entries: scandir("/Applications/TextMate.app/Contents/Resources/PrivilegedTool"): Not a directory
</code></pre>

<p>Then in the text editor:</p>

<pre><code>#StanfordCORENLP
setenv export STANFORDTOOLSDIR=$HOME
setenv export CLASSPATH=$STANFORDTOOLSDIR/stanford-ner-2015-12-09/stanford-ner.jar
setenv export STANFORD_MODELS=$STANFORDTOOLSDIR/stanford-ner-2015-12-09/classifiers
</code></pre>

<p><strong>Update2</strong></p>

<p>I tried the following:</p>

<pre><code>user@MacBook-Pro-de-User:~$ jupyter notebook /Users/user/Jupyter/Project1/Version1 &amp; /Users/user/stanford-ner-2015-12-09
</code></pre>

<p>Then:</p>

<pre><code>---------------------------------------------------------------------------
LookupError                               Traceback (most recent call last)
&lt;ipython-input-1-215fd2418c10&gt; in &lt;module&gt;()
      1 from nltk.tag import StanfordNERTagger
----&gt; 2 st = StanfordNERTagger('english.all.3class.distsim.crf.ser.gz')
      3 #st = StanfordNERTagger('/home/me/stanford/stanford-postagger-full-2015-04-20/classifier/tagger.ser.gz',\
      4                            #'/home/me/stanford/stanford-spanish-corenlp-2015-01-08-models.jar')
      5 st.tag('Rami Eid is studying at Stony Brook University in NY'.split())

/usr/local/lib/python3.5/site-packages/nltk/tag/stanford.py in __init__(self, *args, **kwargs)
    166 
    167     def __init__(self, *args, **kwargs):
--&gt; 168         super(StanfordNERTagger, self).__init__(*args, **kwargs)
    169 
    170     @property

/usr/local/lib/python3.5/site-packages/nltk/tag/stanford.py in __init__(self, model_filename, path_to_jar, encoding, verbose, java_options)
     51                 self._JAR, path_to_jar,
     52                 searchpath=(), url=_stanford_url,
---&gt; 53                 verbose=verbose)
     54 
     55         self._stanford_model = find_file(model_filename,

/usr/local/lib/python3.5/site-packages/nltk/__init__.py in find_jar(name_pattern, path_to_jar, env_vars, searchpath, url, verbose, is_regex)
    717         searchpath=(), url=None, verbose=True, is_regex=False):
    718     return next(find_jar_iter(name_pattern, path_to_jar, env_vars,
--&gt; 719                          searchpath, url, verbose, is_regex))
    720 
    721 

/usr/local/lib/python3.5/site-packages/nltk/__init__.py in find_jar_iter(name_pattern, path_to_jar, env_vars, searchpath, url, verbose, is_regex)
    712                     (name_pattern, url))
    713         div = '='*75
--&gt; 714         raise LookupError('\n\n%s\n%s\n%s' % (div, msg, div))
    715 
    716 def find_jar(name_pattern, path_to_jar=None, env_vars=(),

LookupError: 

===========================================================================
  NLTK was unable to find stanford-ner.jar! Set the CLASSPATH
  environment variable.

  For more information, on stanford-ner.jar, see:
    &lt;http://nlp.stanford.edu/software&gt;
===========================================================================
</code></pre>

<p>Look like you're starting the notebook server from the GUI. The problem is that in OS X, the GUI does not inherit the environment of the shell. You can immediately get it to work by starting the notebook server from the terminal:</p>

<pre><code>jupyter notebook &lt;path-to-notebook-folder&gt; &amp;
</code></pre>

<p>This should let you run with the same environment that your successful <code>python3</code> invocation used. </p>

<p>There <em>are</em> ways to modify the environment of applications launched by the GUI; if you don't mind setting <code>CLASSPATH</code> system-wide, you can set it in <code>/etc/launchd.conf</code> as described <a href="http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x/588442#588442">here</a>. (Log out or restart your system after editing <code>launchd.conf</code>). You could also try <a href="http://stackoverflow.com/questions/7501678/set-environment-variables-on-mac-os-x-lion">this</a> (not sure if it'll still work), or google around for other alternatives.</p>

python osx environment-variables nltk stanford-nlp