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

时间:2014-11-09 19:03:57

标签: python class python-import pexpect

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

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

脚本some_script.py需要使用some_class中的课程some_module.py,因此我按照here的说明进行操作,导入工作正常。

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

some_object = some_class('path to some_module_DIR')

因为some_class需要访问some_module_DIR的内容。这会导致Pexpect引发的非常具体的错误(最后发布以便于阅读),该错误由some_module.py导入。

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

问题:

  • 可能是什么问题?
  • 有任何建议的修复方法吗?

以下是我收到的错误:

注意:错误包含我的原始路径和对我正在使用的模块corenlp的引用(stanford解析器的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

0 个答案:

没有答案