2

My default python is 2.7, but have to do this project in python3.5

I installed pycorenlp through this command line: pip3 install pycorenlp.

And it is showing I have already installed it:

Requirement already satisfied (use --upgrade to upgrade): pycorenlp in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages Requirement already satisfied (use --upgrade to upgrade): requests in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from pycorenlp)

However, when I type python3.5 through terminal to enter into python environment, then type from pycorenlp import StanfordCoreNLP, it is showing error:

ImportError: No module named pycorenlp

I have also tried the solutions here but for python3.5, such as using sudo, chmod, none of them worked.

Do you know how to solve this problem? I have to run the code through the terminal, and have to use pycorenlp

Community
  • 1
  • 1
Cherry Wu
  • 3,844
  • 9
  • 43
  • 63
  • For the record, I'm not able to reproduce your error. I've installed `pycorenlp` for Python 3.5.2 using the same command: `sudo pip3 install pycorenlp`. I'm able to work with the library in my Python script or terminal. I think it is an installation issue for you. – Ni9elF May 31 '17 at 18:05

1 Answers1

1

You could try using the Stanford CoreNLP server if you want to access Stanford CoreNLP in Python. Download available here: http://stanfordnlp.github.io/CoreNLP/download.html

  1. Start the Java server. I'll provide the command here, but you could just as easily add a line of Python code that calls this command with subprocess and starts the server and gets back the process id.

    cd /path/to/stanford-corenlp-full-2016-10-31 ; java -Xmx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000 -annotators tokenize,ssplit,pos,lemma,ner,parse,mention,coref
    

Here is some info on the Java server: http://stanfordnlp.github.io/CoreNLP/corenlp-server.html

Note that is just an example command and you can provide any list of annotators you want.

Now the Java server will be running and you can issue calls to it while your Python program runs. Here is a basic example using the requests library.

  1. Make a basic call to the Stanford CoreNLP server:

    import requests
    
    url = 'http://localhost:9000/?'
    request_params = {'outputFormat': 'json'}
    text = "This is a test sentence."
    r = requests.post(url,data=text,params=request_params)
    print r.json()
    

You will get return JSON with the annotations.

  1. Shut down the server.

There is also a Python wrapper we use internally for accessing the server available in stanza I think the wrapper could work with Python 3, but I am not positive. If you have issues the Python code I provided should work fine with Python 3.

Here is the GitHub for stanza: https://github.com/stanfordnlp/stanza

StanfordNLPHelp
  • 8,699
  • 1
  • 11
  • 9
  • Thank you very much for the answer! I just tried `stanza`, it is showing "no module called stanza" for python3.5 too... But when I tried your first solution, the server is running, however it is showing no module called "requests" and requests has been installed too... So I guess these may be the same problem, maybe some setting problem, I don't know which setting. It seems that everything works pretty good for my python2.7 – Cherry Wu Mar 21 '17 at 02:51
  • You might want to look into Anaconda: https://www.continuum.io/downloads – StanfordNLPHelp Mar 21 '17 at 02:58