简体   繁体   English

subprocess.Popen:仅在Linux上,“ OSError:[Errno 2]没有这样的文件或目录”

[英]subprocess.Popen: 'OSError: [Errno 2] No such file or directory' only on Linux

This is not a duplicate of subprocess.Popen: 'OSError: [Errno 13] Permission denied' only on Linux as that problem occurred due to wrong permissions. 这不是subprocess.Popen的重复项:Popen:“ OSError:[Errno 13]权限被拒绝”仅在Linux上,因为由于权限错误而发生了该问题。 That has been fixed and this is an entirely different problem. 该问题已得到解决,这是一个完全不同的问题。

When my code (given below) executes on Windows (both my laptop and AppVeyor CI), it does what it's supposed to do. 当我的代码(如下所述)在Windows(我的笔记本电脑和AppVeyor CI)上执行时,它会执行应做的事情。 But on Linux (VM on TravisCI), it throws me a file not found error. 但是在Linux(TravisCI上的VM)上,它抛出了一个文件未找到错误。

I am executing in /home/travis/build/sayak-brm/espeak4py/ . 我正在/home/travis/build/sayak-brm/espeak4py/

ls -l outputs: ls -l输出:

$ ls -l
total 48
-rw-rw-r-- 1 travis travis   500 Sep 29 20:14 appveyor.yml
drwxrwxr-x 3 travis travis  4096 Sep 29 20:14 espeak4py
-rw-rw-r-- 1 travis travis 32400 Sep 29 20:14 LICENSE.md
-rw-rw-r-- 1 travis travis  2298 Sep 29 20:14 README.md
-rw-rw-r-- 1 travis travis     0 Sep 29 20:14 requirements.txt
-rw-rw-r-- 1 travis travis   759 Sep 29 20:14 test.py

$ ls -l espeak4py
total 592
-rwxr-xr-x 1 travis travis 276306 Sep 30 06:42 espeak
drwxrwxr-x 5 travis travis   4096 Sep 29 20:14 espeak-data
-rw-rw-r-- 1 travis travis 319488 Sep 29 20:14 espeak.exe
-rw-rw-r-- 1 travis travis   1125 Sep 29 20:14 __init__.py

$ ls -l /home/travis/build/sayak-brm/espeak4py/espeak4py
total 592
-rwxr-xr-x 1 travis travis 276306 Sep 30 06:42 espeak
drwxrwxr-x 5 travis travis   4096 Sep 30 06:42 espeak-data
-rw-rw-r-- 1 travis travis 319488 Sep 30 06:42 espeak.exe
-rw-rw-r-- 1 travis travis   1216 Sep 30 06:42 __init__.py

which shows that the files are where they are supposed to be. 这表明文件位于应有的位置。

The espeak file is a Linux ELF Binary. espeak文件是Linux ELF二进制文件。


Error: 错误:

$ python3 test.py
Testing espeak4py
Testing wait4prev
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    mySpeaker.say('Hello, World!')
  File "/home/travis/build/sayak-brm/espeak4py/espeak4py/__init__.py", line 38, in say
    self.prevproc = subprocess.Popen(cmd, executable=self.executable, cwd=os.path.dirname(os.path.abspath(__file__)))
  File "/opt/python/3.2.6/lib/python3.2/subprocess.py", line 744, in __init__
    restore_signals, start_new_session)
  File "/opt/python/3.2.6/lib/python3.2/subprocess.py", line 1394, in _execute_child
    raise child_exception_type(errno_num, err_msg)
OSError: [Errno 2] No such file or directory: '/home/travis/build/sayak-brm/espeak4py/espeak4py/espeak'

Code: 码:

espeak4py/__init__.py : espeak4py/__init__.py

#! python3
import subprocess
import os
import platform

class Speaker:
    """
    Speaker class for differentiating different speech properties.
    """
    def __init__(self, voice="en", wpm=120, pitch=80):
        self.prevproc = None
        self.voice = voice
        self.wpm = wpm
        self.pitch = pitch
        if platform.system() == 'Windows': self.executable = os.path.dirname(os.path.abspath(__file__)) + "/espeak.exe"
        else: self.executable = os.path.dirname(os.path.abspath(__file__)) + "/espeak"

    def generateCommand(self, phrase):
        cmd = [
            self.executable,
            "--path=.",
            "-v", self.voice,
            "-p", self.pitch,
            "-s", self.wpm,
            phrase
        ]
        cmd = [str(x) for x in cmd]
        return cmd

    def say(self, phrase, wait4prev=False):
        cmd=self.generateCommand(phrase)
        if wait4prev:
            try: self.prevproc.wait()
            except AttributeError: pass
        else:
            try: self.prevproc.terminate()
            except AttributeError: pass
        self.prevproc = subprocess.Popen(cmd, executable=self.executable, cwd=os.path.dirname(os.path.abspath(__file__)))

test.py : test.py

#! python3
import espeak4py
import time

print('Testing espeak4py\n')
print('Testing wait4prev')

mySpeaker = espeak4py.Speaker()

mySpeaker.say('Hello, World!')
time.sleep(1)
mySpeaker.say('Interrupted!')
time.sleep(3)

mySpeaker.say('Hello, World!')
time.sleep(1)
mySpeaker.say('Not Interrupted.', wait4prev=True)
time.sleep(5)

print('Testing pitch')

myHighPitchedSpeaker = espeak4py.Speaker(pitch=120)
myHighPitchedSpeaker.say('I am a demo of the say function')
time.sleep(5)

print('Testing wpm')

myFastSpeaker = espeak4py.Speaker(wpm=140)
myFastSpeaker.say('I am a demo of the say function')
time.sleep(5)

print('Testing voice')

mySpanishSpeaker = espeak4py.Speaker(voice='es')
mySpanishSpeaker.say('Hola. Como estas?')

print('Testing Completed.')

I don't understand why it works only on one platform and not the other. 我不明白为什么它只能在一个平台上运行而不能在另一个平台上运行。

Travis CI Logs: https://travis-ci.org/sayak-brm/espeak4py Travis CI日志: https//travis-ci.org/sayak-brm/espeak4py

AppVeyor Logs: https://ci.appveyor.com/project/sayak-brm/espeak4py AppVeyor日志: https ://ci.appveyor.com/project/sayak-brm/espeak4py

GitHub: https://sayak-brm.github.io/espeak4py GitHub: https : //sayak-brm.github.io/espeak4py

I've tested your espeak Python wrapper on Linux, and it works for me. 我已经在Linux上测试了您的espeak Python包装器,它对我espeak Probably it's just an issue with Windows trailing \\r characters. Windows尾随\\r字符可能只是一个问题。 You could try the following: 您可以尝试以下方法:

sed -i 's/^M//' espeak4py/__init__.py

To enter the ^M , type Ctrl-V followed by Ctrl-M , and see if running that sed command solves the issue. 要输入^M ,请依次输入Ctrl-VCtrl-M ,然后查看运行该sed命令是否可以解决此问题。

The Linux binary packaged with the repo is not compatible with the Travis Build Architecture and the binary needs t be built from source before it is executed. 与回购协议一起打包的Linux二进制文件与Travis Build Architecture不兼容,并且在执行之前不需要从源代码中构建二进制文件。

Instructions for buiding: https://github.com/rhdunn/espeak#building-1 建立说明: https : //github.com/rhdunn/espeak#building-1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 subprocess.Popen:&#39;OSError:[Errno 13]权限被拒绝&#39;仅在Linux上 - subprocess.Popen: 'OSError: [Errno 13] Permission denied' only on Linux Python:subprocess.Popen返回OSError:[Errno 2]没有这样的文件或目录 - Python: subprocess.Popen returns OSError: [Errno 2] No such file or directory Python:OSError:[Errno 2] subprocess.Popen上没有这样的文件或目录 - Python: OSError: [Errno 2] No such file or directory on subprocess.Popen subprocess.Popen [Errno 2]没有这样的文件或目录 - subprocess.Popen [Errno 2] No such file or directory pygtk OSError:[Errno 2]没有这样的文件或目录。 subprocess.Popen PIPE命令 - pygtk OSError: [Errno 2] No such file or directory. subprocess.Popen PIPE command Python,使用subprocess.Popen进行linux命令行调用?我得到“[Errno 2]没有这样的文件或目录” - Python, using subprocess.Popen to make linux command line call? I'm getting “[Errno 2] No such file or directory” Pyton 3.10 中的 subprocess.POpen [Errno 2] 没有这样的文件或目录 - subprocess.POpen in Pyton 3.10 [Errno 2] No such file or directory subprocess.Popen(): OSError: [Errno 8] python 中的 Exec 格式错误? - subprocess.Popen(): OSError: [Errno 8] Exec format error in python? OSError:运行subprocess.Popen时出现[Errno 8] Exec格式错误 - OSError: [Errno 8] Exec format error when running subprocess.Popen Python subprocess.Popen “OSError: [Errno 12] 无法分配内存” - Python subprocess.Popen "OSError: [Errno 12] Cannot allocate memory"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM