stanford corenlp not working

北战南征 提交于 2020-01-22 15:13:45

问题


I'm using Windows 8, and running python in eclipse with pyDev.

I installed Stanford coreNLP (python version) from the site: https://github.com/relwell/stanford-corenlp-python

When I try to import corenlp, I get the following error message.

Traceback (most recent call last):
  File "C:\Users\Ghantauke\workspace\PythonTest2\test.py", line 1, in <module>
    import corenlp
  File "C:\Python27\lib\site-packages\corenlp\__init__.py", line 13, in <module>
    from corenlp import StanfordCoreNLP, ParserError, TimeoutError, ProcessError
  File "C:\Python27\lib\site-packages\corenlp\corenlp.py", line 28, in <module>
    import pexpect
  File "C:\Python27\lib\site-packages\pexpect.py", line 85, in <module>
    support it. Pexpect is intended for UNIX-like operating systems.""")
ImportError: No module named resource

A critical module was not found. Probably this operating system does not
support it. Pexpect is intended for UNIX-like operating systems.

Does that mean the python fork of it doesn't work in windows? Is there any way I can make it work in windows?

If not then could you suggest other alternatives that I could use in windows. I just need the parser.


回答1:


This is a record of my attempts to get corenlp-python, the python wrapper for CoreNLP running on Windows Server 2012, as-is.

Disclaimer: should you only need to run an executable, check this first. Consider subprocess.

Starting out

Since corenlp-python uses pexpect fairly heavily, and that library works on UNIX only, my first thought was to find a Windows port.

wexpect.py was fairly easy to find and claims to be a drop-in replacement for Pexpect (emphasis mine):

In order to use WExpect, you must install CygWin, and then install the WExpect script into your system (dropping the py file into your working directory is usually good enough). I’ve found the functionality is pretty much the same, so you should be able to use the PExpect manual and examples and apply them to this Microsoft Windows variant.

So I did just that, downloading and installing CygWin, then copying wexpect.py into C:\Python27\lib\ where all the other libraries were. I tried to import wexpect from a Python shell and got an error similar to when I first tried Pexpect on Windows:

ImportError: No module named pywintypes
This module requires the win32 python packages.

A critical module was not found. Probably this operating system does not
support it. Pexpect is intended for UNIX-like systems.

Et tu, wexpect?

No matter, this is standard frustration for finding equivalents. Press on.

I opened wexpect.py and saw that it would only try pywintypes on a Windows system. Logical, so I tried:

$ pip install -U pywintypes

...which failed, and led me to Google for the name of the python Win32 packages (this answer helped):

$ pip install -U pywin32

...which prompts for --allow-external and then --allow-unverified, both of which expect the package name, ergo:

$ pip install --allow-external pywin32 --allow-unverified pywin32 pywin32

Which, of course, does not work. No such package is found.

sf.net

So I head off to search for pywin32 on PyPI and realise that only a readme is left and I have to jump through four MORE hoops to get to something more substantial, then two more to find this list.

I downloaded Build 219 for Python 2.7 32-bit. At least now import wexpect doesn't puke.

What did you expect?

So I run the corenlp-python command again, and this time it's missing unidecode. This was easier to fix, and finally I got to a usable state - an error, no less, but familiar - where the path to the JARs was not correct.

OK.

When you run corenlp.py, since pexpect is invoked, remember to import wexpect as pexpect near the top and comment out the real import pexpect line, or you will get a NameError:

#import pexpect
import wexpect as pexpect

Even with Java installed, this does not seem to work, regardless of path.

$ python lib\corenlp\corenlp.py

It returns an ExceptionPexpect.



来源:https://stackoverflow.com/questions/18704590/stanford-corenlp-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!