1

New to Python 3.6 with Mac...Was trying to use NLTK with Stanford NLP.

(1) was totally not able to understand environment variables and can't set correctly when using Stanford NLP. I tried the following but run out of idea when arriving at STEP3,

Add the appropriate Stanford NLP .jar file to the CLASSPATH environment variable.

Stanford Parser and NLTK

Wondering whether some guys can explain patiently how the CLASSPATH works and how to set them with/before NLTK (export codes are disabled in NLTK)

Although setting environment variables is a much elegant way, I have to choose the alternative. I downloaded all jar files and put them on my desktop. (No idea where they should be placed. Most related instructions deals with Windows, which does not work for Mac).

Therefore, tried to specify the locations of Stanford NLP tools, such as follows

screenshot of the codes and how they failed in the interpreter

Hope to solve it! Thanks much!!!!

X. Xing
  • 11
  • 2

1 Answers1

0

To set an environment variable globally, run

export CLASSPATH="path/to/file.jar"

from the terminal (iTerm or iTerm2 on mac) or

export CLASSPATH=`pwd`/file.jar

if you're in the folder where file.jar is located.

To set an environment variable in a python script:

import os
os.environ['CLASSPATH'] = 'path/to/file.jar'

Note that in a python script, the values will not be availabile after that script has run.

Daniel Lee
  • 7,189
  • 2
  • 26
  • 44