weixin_41505090 2020-09-26 13:24 采纳率: 0%
浏览 908

python3遇到了OSError: [Errno 22] Invalid argument

[quote=引用 楼主 萝卜的兔几 的回复:]这是我从网上下载的代码,运行的环境是Python3。一直报这样的错,改了几次也没有成功。求问大神有没有知道怎么改的。。
import os
import sys
import subprocess
import threading

Assumes meteor-1.5.jar is in the same directory as meteor.py. Change as needed.

METEOR_JAR = 'meteor-1.5.jar'

print METEOR_JAR

class Meteor:

def __init__(self):
    self.meteor_cmd = ['java', '-jar', '-Xmx2G', METEOR_JAR, \
            '-', '-', '-stdio', '-l', 'en', '-norm']
    self.meteor_p = subprocess.Popen(self.meteor_cmd, \
            cwd=os.path.dirname(os.path.abspath(__file__)), \
            stdin=subprocess.PIPE, \
            stdout=subprocess.PIPE, \
            stderr=subprocess.PIPE)
    # Used to guarantee thread safety
    self.lock = threading.Lock()

def compute_score(self, gts, res):
    assert(list(gts.keys()) == list(res.keys()))
    imgIds = list(gts.keys())
    scores = []

    eval_line = 'EVAL'
    self.lock.acquire()
    for i in imgIds:
        assert(len(res[i]) == 1)
        stat = self._stat(res[i][0], gts[i])
        eval_line += ' ||| {}'.format(stat)

    self.meteor_p.stdin.write('{}\n'.format(eval_line))
    for i in range(0,len(imgIds)):
        scores.append(float(self.meteor_p.stdout.readline().strip()))
    score = float(self.meteor_p.stdout.readline().strip())
    self.lock.release()

    return score, scores

def method(self):
    return "METEOR"

def _stat(self, hypothesis_str, reference_list):
    # SCORE ||| reference 1 words ||| reference n words ||| hypothesis words
    hypothesis_str = hypothesis_str.replace('|||','').replace('  ',' ')
    score_line = ' ||| '.join(('SCORE', ' ||| '.join(reference_list), hypothesis_str))
    self.meteor_p.stdin.write('{}\n'.format(score_line))
    return self.meteor_p.stdout.readline().strip()

def _score(self, hypothesis_str, reference_list):
    self.lock.acquire()
    # SCORE ||| reference 1 words ||| reference n words ||| hypothesis words
    hypothesis_str = hypothesis_str.replace('|||','').replace('  ',' ')
    score_line = ' ||| '.join(('SCORE', ' ||| '.join(reference_list), hypothesis_str))
    self.meteor_p.stdin.write('{}\n'.format(score_line))
    stats = self.meteor_p.stdout.readline().strip()
    eval_line = 'EVAL ||| {}'.format(stats)
    # EVAL ||| stats 
    self.meteor_p.stdin.write('{}\n'.format(eval_line))
    score = float(self.meteor_p.stdout.readline().strip())
    # bug fix: there are two values returned by the jar file, one average, and one all, so do it twice
    # thanks for Andrej for pointing this out
    score = float(self.meteor_p.stdout.readline().strip())
    self.lock.release()
    return score

def __del__(self):
    self.lock.acquire()
    self.meteor_p.stdin.close()
    self.meteor_p.kill()
    self.meteor_p.wait()
    self.lock.release()

报的错误是
[img=https://img-bbs.csdn.net/upload/201905/16/1557999976_286924.png][/img][/quote]

目前遇到的是一样的问题,原帖尚未有解决方案,诚心求教

  • 写回答

3条回答 默认 最新

  • evergreen79 2020-09-26 14:31
    关注

    这段代码是在linux上运行的,你是否用在windows 上了?显示OSError

    评论

报告相同问题?

悬赏问题

  • ¥15 机器学习预测遇到的目标函数问题
  • ¥15 python的EOFError该怎么解决?
  • ¥15 Fluent,液体进入旋转区域体积分数不连续
  • ¥15 java linux下将docx文件转pdf
  • ¥15 maven无法下载依赖包
  • ¥15 关于pycharm, Callable[[str],bool]作为方法参数使用时, lambda 类型不提示问题
  • ¥15 layui数据重载无效
  • ¥15 寻找了解qq家园纵横四海的程序猿。
  • ¥15 optisystem
  • ¥15 VB.NET画图时的撤销编程