简体   繁体   English

python为什么找不到我的文件?

[英]Why can't python find my file?

So someone wrote a joke trapifier script (as in, 'Trap music') and I can't get it to work. 因此有人写了一个笑话陷阱脚本(例如“诱捕音乐”),但我无法使其正常工作。

usage: trapifier.py [-h] [--samples [SAMPLES]] inputfile outputfile

Yet, despite the folder looking like this 然而,尽管文件夹看起来像这样

ls -l
total 14288
-rwxrwxrwx   1 ________  ________  7295612 Mar  2  2008 Chicago.mp3
-rwxr-xr-x@  1 ________  ________     1074 Apr 12 17:00 LICENSE
-rwxr-xr-x@  1 ________  ________     2871 Apr 12 17:00 README.md
-rwxr-xr-x@  1 ________  ________        6 Apr 12 17:00 requirements.txt
drwxr-xr-x@ 48 ________  ________     1632 Apr 12 17:00 samples
-rwxr-xr-x   1 ________  ________     2923 Apr 12 17:00 trapifier.py

This command always results in a [Errno 2] No such file or directory 此命令总是导致[Errno 2]没有这样的文件或目录

./trapifier.py Chicago.mp3 Chiraq.mp3

or 要么

python trapifier.py Chicago.mp3 Chiraq.mp3

or even 甚至

./trapifier.py /full/path/to/Chicago.mp3 Chiraq.mp3

What gives? 是什么赋予了? I feel like there is a rookie mistake somewhere. 我觉得某个地方有个菜鸟错误。

The full error message by request: 根据请求的完整错误消息:

    Traceback (most recent call last):
  File "./trapifier.py", line 89, in <module>
    overlay(parse())
  File "./trapifier.py", line 32, in parse
    base_track = pydub.AudioSegment.from_mp3(inputfile)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydub/audio_segment.py", line 297, in from_mp3
    return cls.from_file(file, 'mp3')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydub/audio_segment.py", line 284, in from_file
    subprocess.call(convertion_command, stderr=open(os.devnull))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 679, in     __init__
    errread, errwrite)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1249,     in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Source of the script is hosted at https://github.com/japesinator/trapifier.py 该脚本的源代码托管在https://github.com/japesinator/trapifier.py

I have all the required libraries (argparse, pydub, os, random). 我拥有所有必需的库(argparse,pydub,os,random)。

First Useful Edit: It appears that pydub.AudioSegment failing to load is the culprit. 第一个有用的编辑:似乎是pydub.AudioSegment无法加载,是罪魁祸首。 However, things get stranger. 但是,事情变得陌生。 In a python terminal I can do 在python终端中,我可以做

from pydub import AudioSegment

but I get a no such module error when I do 但是当我这样做时,没有得到这样的模块错误

import pydub.AudioSegment 导入pydub.AudioSegment

It's pretty common that pydub cannot find ffmpeg which is used to decode and encode mp3 files (and all other non-wave formats). pydub找不到用于解码和编码mp3文件(以及所有其他非wave格式)的ffmpeg是很常见的。 If you have ffmpeg installed and it is still not working you can explicitly tell pydub where to find it like so: 如果您安装了ffmpeg,但仍无法正常工作,则可以明确告诉pydub在哪里找到它,如下所示:

from pydub import AudioSegment
AudioSegment.ffmpeg = "/path/to/ffmpeg"

You may also find our getting ffmpeg set up docs helpful =D 您可能还会发现我们对ffmpeg设置文档很有帮助= D

edit – Last resort option : If you can't get get pydub to find ffmpeg despite your best efforts you could convert everything to wave format before passing the files to pydub. 编辑– 不得已的选择 :如果尽最大努力仍无法使pydub查找ffmpeg,则可以在将文件传递到pydub之前将所有内容转换为wave格式。 This is a last resort for sure, but it would circumvent the ffmpeg issue since pydub supports wave natively. 可以肯定,这是最后的手段,但是由于pydub本身支持wave,因此可以避免ffmpeg问题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM