Search code examples
python-2.7cmdpexpect

winexpect import in a .py not working when running through cmd


Why I am getting this error, when I try to run it through python corenlp.py?

Traceback (most recent call last):
File "corenlp.py", line 23, in (module)
from winpexpect import winspawn
File "C:\Python27\1ib\site-packages\winpexpect-1.5-py2.7.egg\winpexpect.py", 1ine 391, in (module)
class winspawn(spawn):
TypeError: Error when calling the metaclass bases
function() argument 1 must be code, not str

But, When i use it in PythonShell GUI, it is working perfectly.

from winpexpect import winspawn
child = winspawn('java -cp "C:\\Python27\\Scripts\\stanford-corenlp-full-2014-08-27\\*" -Xmx2g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,parse,dcoref -ner.model edu/stanford/nlp/models/ner/english.all.3class.caseless.distsim.crf.ser.gz')

Solution

  • Finally I was able to resolve my problem(Thanks to @MichaelPetch). I tried this simple example test.py

    from winpexpect import winspawn
    child=winspawn("java")
    

    It was working fine. Then I realized something wrong with my imports or dependencies. I was using wexpect.py which is another alternative for windows. I renamed it to pexpect.py and copied to my code base.

    But winpexpect has dependencies for pexpect(it has another pexpect file on its own folder). When I try to run my .py through cmd it is referring the file in the same folder which is pexpect, I just renamed.

    Solution: I just removed wexpect.