我正在尝试使用gensim wordrank包装器训练自己的数据。我正在跟踪this链接到训练模型。我已将'path_to_wordrank_binary'变量设置为包含wordrank.cpp文件的Ubuntu系统上wordrank目录的路径。但仍然出现以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/gensim/models/wrappers/wordrank.py", line 229, in train
utils.check_output(args=cmd)
File "/usr/local/lib/python2.7/dist-packages/gensim/utils.py", line 1870, in check_output
process = subprocess.Popen(stdout=stdout, shell=True, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
下面是从wordrank.py文件中调用util.check_out方法的代码:
# run wordrank executable with wr_args
cmd = ['mpirun', '-np', str(np), os.path.join(wr_path, 'wordrank')]
for option, value in wr_args.items():
cmd.append('--%s' % option)
cmd.append(str(value))
logger.info("Running wordrank binary")
utils.check_output(args=cmd)
以下是utils.py文件中check_out函数的代码:
def check_output(stdout=subprocess.PIPE, *popenargs, **kwargs):
r"""Run OS command with the given arguments and return its output as a byte string.
Backported from Python 2.7 with a few minor modifications. Widely used for :mod:`gensim.models.wrappers`.
Behaves very similar to https://docs.python.org/2/library/subprocess.html#subprocess.check_output.
Examples
--------
>>> from gensim.utils import check_output
>>> check_output(args=['echo', '1'])
'1\n'
Raises
------
KeyboardInterrupt
If Ctrl+C pressed.
"""
try:
logger.debug("COMMAND: %s %s", popenargs, kwargs)
process = subprocess.Popen(stdout=stdout, shell=True, *popenargs, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
error = subprocess.CalledProcessError(retcode, cmd)
error.output = output
raise error
return output
except KeyboardInterrupt:
process.terminate()
raise
我试图解决此问题。其他所有解决方案都建议将shell=True
作为Popen
函数的参数。我也尝试过,但是无法解决问题。
有人可以帮我吗?