AttributeError:模块“moviepy.audio.fx.all”没有属性“audio_fadein”

问题描述

通过 auto-py-to-exe 或 pyinstaller 将我的代码转换为 exe 后,我收到以下与 moviepy 相关的错误。我需要moviepy的原因是我无法在使用变量名时转换为mp4,尽管在下面看到的代码中设置为字符串时我可以。据我所知,我已经安装了所有必要的库,即使在通过 Anaconda CMD.exe Prompt 运行时我也有同样的错误。我曾尝试使用 Internet 上的解决方案,但它们似乎涉及修改某些无法解决问题的 init 文件,或者从moviepy 导入子模块,这些子模块不再适用于我的代码。我已经尝试了我在互联网上看到的一切,但都没有成功。任何帮助将不胜感激。哦,顺便说一句,它作为 .py 文件工作得很好。它仅在转换为 exe 时中断。那么在转换为涉及 moviepy 的 exe 时可能缺少依赖项?以下是我的错误信息:

Traceback (most recent call last):
  File "cdn_python_script.py",line 3,in <module>
  File "<frozen importlib._bootstrap>",line 1007,in _find_and_load
  File "<frozen importlib._bootstrap>",line 986,in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>",line 680,in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py",line 531,in exec_module
  File "moviepy\editor.py",line 87,in <module>
  File "<string>",line 1,in <module>
AttributeError: module 'moviepy.audio.fx.all' has no attribute 'audio_fadein'
[11968] Failed to execute script cdn_python_script

这是我的源代码

# libraries imported for usage within the written code.
import requests
import moviepy.editor as moviepy
import os

# shows menu of options for the user to select from in range of 1-4.
print("Type 1 to Download a video of the Earth")
print("Type 2 to Download a video of an animated Rabbit")
print("Type 3 to Download a video of an Ocean")
print("Type 4 to Download a video of Sea Life")

# starts a loop so that the message is continuously repeated if necessary due to try and except functions.
while True:
    try:
        # user input saves to variable name message for future use in functions.
        message = int(
            # user is prompted to enter a value on their keyboard which is checked against requirements and rules.
            input(
                "Choose a video from the above menu,then enter the corresponding number and press enter: "
            )
        )
    # checks for value of user input as to ensure number is selected otherwise repeats question.
    except ValueError:
        print("Sorry,please enter a number.")
        # if the input is a number then the loop continues instead of looping back to the start.
        continue

    # part of the loop that makes sure the variable message isn't 0 or below as to ensure it is within the range of 1-4.
    if message <= 0:
        print("Sorry,your response was not within the range of 1-4.")
    # part of the loop that makes sure the variable message isn't above 4 as to ensure it is within the range of 1-4.
    elif message > 4:
        print("Sorry,your response was not within the range of 1-4.")
        continue
    # if input is a number within the correct range then it makes it to this code where the loop breaks.
    else:
        # selected number was successfully parsed,and we're happy with its value.
        # we're ready to exit the loop.
        break

# checks the value saved in the variable message is eitehr 1,2,3 or 4 and if so prints video selected.
if message in range(1,5):
    print("Video Selected")
# checks the variable message is eitehr 1,3 or 4 and if not prints video not seelcted and will run prevIoUs loop.
else:
    print("Video not selected.")

# runs the correct block of code depending on if user selected 1,3 or 4 based on user input saved to the variable.
if message == 1:
    # saves the below string (URL) to variable name file_url.
    file_url = "https://myawsbuckettest12321.s3.eu-west-2.amazonaws.com/file_example_MP4_1920_18MG.mp4"
    # requests.get function saved to variable r and uses the saved file_url for the download later on.
    # requests library is used here within this code.
    r = requests.get(file_url,stream=True)

elif message == 2:
    file_url = (
        "https://myawsbuckettest12321.s3.eu-west-2.amazonaws.com/sample-mp4-file.mp4"
    )
    r = requests.get(file_url,stream=True)

elif message == 3:
    file_url = (
        "https://myawsbuckettest12321.s3.eu-west-2.amazonaws.com/sample_1280x720.mp4"
    )
    r = requests.get(file_url,stream=True)

elif message == 4:
    file_url = "https://myawsbuckettest12321.s3.eu-west-2.amazonaws.com/sample_960x400_ocean_with_audio.mp4"
    r = requests.get(file_url,stream=True)

# prompts the user to enter a name for the file and the input is then saved to file_name.
# the prompt from the user is to avoid overwriting files if the user downloads multiple videos because of a set string.
file_name = input("Please give the video a name to save as,then press enter: ")
print("Please wait while your video is downloading...")

# takes the file_name value depending on number selected earlier,opens file in binary mode and attempts to save as mp4.
with open(file_name,"wb") as mp4:
    for chunk in r.iter_content(chunk_size=1024):

        # writing one chunk at a time to mp4 file.
        if chunk:
            mp4.write(chunk)

# file_name variable above does not save as mp4 while it does if set as a string instead of a variable.
# therefore,moviepy library is used here to convert the file after downloaded to mp4 format to view the video.
clip = moviepy.VideoFileClip(file_name)
# saves the video as file_name (what the user named the file) plus .mp4 to ensure it always has the correct file format.
clip.write_videofile(file_name + ".mp4")

# os library is imported here because the converted mp4 and original file still exist.
# this line simply deleted the original file leaving the mp4 as it looks for the file_name without the mp4 on the end.
os.remove(file_name)

# startfile function from within the os library is used here to autoplay the downloaded and converted mp4 for the user.
from os import startfile

# file_input meaning what the user named the file as plus .mp4 is found once downloaded so as to play the mp4.
startfile(file_name + ".mp4")

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...