创建类的对象时出现Python PExpect错误

2024-05-15 10:45:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我按照以下方式组织Python工作区:Scripts目录包含我自己编写的代码;Modules目录包含我需要导入并在代码中使用的第三方模块。以下是陈述:

/PythonWorkspace/
     /Scripts
         some_script.py
     /Modules
         __init__.py
         some_module.py
         some_module_DIR

脚本some_script.py需要使用来自some_module.py的类some_class,所以我按照找到here的说明进行操作,导入工作正常。在

要创建some_module.py中包含的类的对象,我使用

^{pr2}$

由于cd4{cd8}的内容需要访问。这会导致^{}引发的一个非常具体的错误(为了可读性,在结尾处发布),该错误由some_module.py导入。在

奇怪的是,如果我将some_script.py复制到/Modules并从那里运行它,那么在创建some_class类的对象时不会出错。但是,在后一种情况下,我使用some_object = some_class(),因为本例中使用了默认路径。在

问题:

  • 有什么问题吗?在
  • 有什么建议吗?在

这是我得到的错误:

注意:错误包含我的原始路径和对我正在使用的模块corenlp的引用(斯坦福解析器的python包装器)。在

In [19]: corenlp = StanfordCoreNLP('./stanfordParserPython/stanford-corenlp-full-2014-08-27/')
---------------------------------------------------------------------------                               
EOF                                       Traceback (most recent call last)
/home/matteorr/Cluster/home/research/SceneUnderstanding/<ipython-input-19-97d07e470ae5> in <module>()
----> 1 corenlp = StanfordCoreNLP('./stanfordParserPython/stanford-corenlp-full-2014-08-27/')

/home/matteorr/Cluster/home/research/SceneUnderstanding/corenlp.pyc in __init__(self, corenlp_path)
    166         widgets = ['Loading Models: ', Fraction()]
    167         pbar = ProgressBar(widgets=widgets, maxval=5, force_update=True).start()
--> 168         self.corenlp.expect("done.", timeout=20) # Load pos tagger model (~5sec)
    169         pbar.update(1)
    170         self.corenlp.expect("done.", timeout=200) # Load NER-all classifier (~33sec)

/usr/lib/python2.7/dist-packages/pexpect.pyc in expect(self, pattern, timeout, searchwindowsize)
   1309 
   1310         compiled_pattern_list = self.compile_pattern_list(pattern)
-> 1311         return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
   1312 
   1313     def expect_list(self, pattern_list, timeout = -1, searchwindowsize = -1):

/usr/lib/python2.7/dist-packages/pexpect.pyc in expect_list(self, pattern_list, timeout, searchwindowsize)
   1323         self.searchwindowsize value is used. """
   1324 
-> 1325         return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
   1326 
   1327     def expect_exact(self, pattern_list, timeout = -1, searchwindowsize = -1):

/usr/lib/python2.7/dist-packages/pexpect.pyc in expect_loop(self, searcher, timeout, searchwindowsize)
   1394                 self.match = None
   1395                 self.match_index = None
-> 1396                 raise EOF (str(e) + '\n' + str(self))
   1397         except TIMEOUT, e:
   1398             self.buffer = incoming

EOF: End Of File (EOF) in read_nonblocking(). Exception style platform.
<pexpect.spawn object at 0x2a4fdd0>
version: 2.3 ($Revision: 399 $)
command: /usr/bin/java
args: ['/usr/bin/java', '-Xmx1800m', '-cp', './stanfordParserPython/stanford-corenlp-full-2014-08-27/stanford-corenlp-3.4.1.jar:./stanfordParserPython/stanford-corenlp-full-2014-08-27/stanford-corenlp-3.4.1-models.jar:./stanfordParserPython/stanford-corenlp-full-2014-08-27/joda-time.jar:./stanfordParserPython/stanford-corenlp-full-2014-08-27/xom.jar:./stanfordParserPython/stanford-corenlp-full-2014-08-27/jollyday.jar', 'edu.stanford.nlp.pipeline.StanfordCoreNLP', '-props', 'default.properties']
searcher: searcher_re:
    0: re.compile("done.")
buffer (last 100 chars): 
before (last 100 chars): va:448)
    at edu.stanford.nlp.util.StringUtils.argsToProperties(StringUtils.java:869)
    ... 2 more

after: <class 'pexpect.EOF'>
match: None
match_index: None
exitstatus: None
flag_eof: True
pid: 22440
child_fd: 7
closed: False
timeout: 30
delimiter: <class 'pexpect.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1

Tags: pyselfnonetimeoutsomefulllistexpect