title: py4j.protocol.Py4JNetworkError: An error occurred while trying to connect to the Java server
body: <p>I m trying to understand this code which uses Py4j. However each time I run the code I'm getting the same error. I have py4j installed in my Ubuntu 14.04. The jar file is in usr/share/py4j. </p>
  
  <p>The code is</p>
  
  <pre><code>from nltk.tokenize.punkt import PunktSentenceTokenizer, PunktParameters
  from nltk.tokenize import wordpunct_tokenize , sent_tokenize
  from py4j.java_gateway import JavaGateway
  import nltk
  from nltk.tree import Tree
  import os.path
  import parsers
  
  LangPaths =os.path.realpath("/home/Downloads/Abstractive Summarizer/SumMe-master/Summarizer/langdetector/profiles/")
  tltagger = nltk.data.load("taggers/english.pickle")
  tlChunker = nltk.data.load("chunkers/maxent_ne_chunker/english_ace_binary.pickle")
  enChunker = nltk.data.load("chunkers/maxent_ne_chunker/english_ace_multiclass.pickle")
  punkt_param  = PunktParameters()  #creates an opening for tokenizer parameters.
  punkt_param.abbrev_types = set(['gng','mr','mrs','dr','rep']) #abbreviations further accepted goes here
  sentence_splitter = PunktSentenceTokenizer(punkt_param)
  tokenized = ""
  gateway = JavaGateway()
  detector = gateway.entry_point
  detector.init(LangPaths)
  </code></pre>
  
  <p>The error which I m getting is</p>
  
  <blockquote>
    <p>File "/home/shiju/Downloads/Abstractive
    Summarizer/SumMe-master/Summarizer/preprocessor.py", line 29, in
    
        detector.init(LangPaths)</p>
    
    <p>File "/usr/local/lib/python2.7/dist-packages/py4j/java_gateway.py",
    line 811, in __call_   answer =
    self.gateway_client.send_command(command)`</p>
    
    <p>File "/usr/local/lib/python2.7/dist-packages/py4j/java_gateway.py",
    line 624, in send_command
        connection = self._get_connection()</p>
    
    <p>File "/usr/local/lib/python2.7/dist-packages/py4j/java_gateway.py",
    line 579, in _get_connection
        connection = self._create_connection()   File "/usr/local/lib/python2.7/dist-packages/py4j/java_gateway.py", line
    585, in _create_connection
        connection.start()</p>
    
    <p>File "/usr/local/lib/python2.7/dist-packages/py4j/java_gateway.py",
    line 697, in start
        raise Py4JNetworkError(msg, e) py4j.protocol.Py4JNetworkError: An error occurred while trying to connect to the Java server</p>
  </blockquote>
  
  <p>I think Python is unable to connect with the Java application</p>