【问题标题】:Error importing VideoFileClip from moviepy : AttributeError: 'PermissionError' object has no attribute 'message'从moviepy导入VideoFileClip时出错:AttributeError:'PermissionError'对象没有属性'message'
【发布时间】:2017-07-02 19:05:48
【问题描述】:

我正在使用 jupyter 笔记本。我也从 anaconda 控制台尝试过。

尝试使用以下两种方式导入

from moviepy.editor import VideoFileClip

from moviepy.video.io.VideoFileClip import VideoFileClip

他们都给了我同样的错误。完整的跟踪如下

AttributeError                            Traceback (most recent call last)
<ipython-input-10-9afa9d6e87c4> in <module>()
      6 import glob
      7 import math
----> 8 from moviepy.editor import VideoFileClip
      9 from moviepy.video.io.VideoFileClip import VideoFileClip

C:\Program Files\Anaconda3\lib\site-packages\moviepy\editor.py in <module>()
     20 # Clips
     21 
---> 22 from .video.io.VideoFileClip import VideoFileClip
     23 from .video.io.ImageSequenceClip import ImageSequenceClip
     24 from .video.io.downloader import download_webfile

C:\Program Files\Anaconda3\lib\site-packages\moviepy\video\io\VideoFileClip.py in <module>()
      1 import os
      2 
----> 3 from moviepy.video.VideoClip import VideoClip
      4 from moviepy.audio.io.AudioFileClip import AudioFileClip
      5 from moviepy.Clip import Clip

C:\Program Files\Anaconda3\lib\site-packages\moviepy\video\VideoClip.py in <module>()
     18 
     19 import moviepy.audio.io as aio
---> 20 from .io.ffmpeg_writer import ffmpeg_write_image, ffmpeg_write_video
     21 from .io.ffmpeg_tools import ffmpeg_merge_video_audio
     22 from .io.gif_writers import (write_gif,

C:\Program Files\Anaconda3\lib\site-packages\moviepy\video\io\ffmpeg_writer.py in <module>()
     13     DEVNULL = open(os.devnull, 'wb')
     14 
---> 15 from moviepy.config import get_setting
     16 from moviepy.tools import verbose_print
     17 

C:\Program Files\Anaconda3\lib\site-packages\moviepy\config.py in <module>()
     49     success, err = try_cmd([FFMPEG_BINARY])
     50     if not success:
---> 51         raise IOError(err.message +
     52                  "The path specified for the ffmpeg binary might be wrong")
     53 

AttributeError: 'PermissionError' object has no attribute 'message'

Python 版本信息

Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul  5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

在控制台中运行 ffmpeg -version 给我

ffmpeg version N-83507-g8fa18e0 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 5.4.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
libavutil      55. 47.100 / 55. 47.100
libavcodec     57. 80.100 / 57. 80.100
libavformat    57. 66.102 / 57. 66.102
libavdevice    57.  2.100 / 57.  2.100
libavfilter     6. 73.100 /  6. 73.100
libswscale      4.  3.101 /  4.  3.101
libswresample   2.  4.100 /  2.  4.100
libpostproc    54.  2.100 / 54.  2.100

我运行的是 64 位版本的 Windows 10。

我在任何地方都找不到任何解决方案,这让我发疯!似乎它没有找到 ffmpeg 二进制文件,但我已将其放入 C:\ffmpeg\bin 并将其添加到路径环境变量中。遵循here的指示。

【问题讨论】:

    标签: python windows python-3.x ffmpeg anaconda


    【解决方案1】:

    今晚我只需要自己解决这个问题。这个错误有两个部分:

    1> message 属性在 Python 3 中不再存在于异常对象上,并且

    2> 如你所料,你需要告诉 MoviePy FFMpeg 在哪里

    要解决err.message 属性错误,可以将其替换为str(err)

        raise IOError(str(err) + 
                 "The path specified for the ffmpeg binary might be wrong")
    

    但是真正的解决方案是确保 MoviePy 知道 FFMpeg 在哪里。查看您的moviepy\config_defaults.py 文件,看看它对FFMPEG_BINARY 的含义。默认值为os.getenv('FFMPEG_BINARY', 'ffmpeg-imageio'),这意味着它将第一个值视为包含FFMpeg 可执行文件路径的环境变量,如果未找到将使用第二个值。这意味着它应该使用由imageio 模块安装的FFMpeg。

    由于您已经在计算机上的某个位置安装了 FFMpeg,您只需在 config_defaults.py 中设置 FFMPEG_BINARY 变量以指向它:

    FFMPEG_BINARY = "c:\FFMPEG\ffmpeg.exe" # where ever it is on your system
    

    或者您可以使用该值创建一个环境变量。

    如果您还没有安装 FFMpeg,您可以通过 ImageIO 安装它,ImageIO 是 MoviePy 使用和安装的模块。在MoviePy install instructions 中,他们提到FFMpeg 应该由ImageIO 自动安装,但这对我来说并没有发生。当它导致错误时,它会为您提供手动安装的说明:

    imageio.core.fetching.NeedDownloadError: Need ffmpeg exe. You can download it by calling:
      imageio.plugins.ffmpeg.download()
    

    这就是我所做的,无需为此编辑config_defaults.py。我没有使用过 Anaconda,但我在 WinPython 中使用它,这是另一种 Python 一体式发行版。

    我遇到这个错误的原因是我在config_defaults.py 中错误地输入了 ImageMagick 的路径,导致“raise”分支运行,暴露了 Python 2 代码来设置 err.message。

    希望这个迂回的故事对你或其他人有所帮助。

    【讨论】:

    • 我通过编辑 config.py 文件修复了它。那里有 3 个 ffmpeg 加载选项。而且是选错了。所以我修改了代码,使其采用适当的代码:)
    猜你喜欢
    • 2021-02-03
    • 1970-01-01
    • 1970-01-01
    • 2019-08-01
    • 1970-01-01
    • 2022-12-21
    • 2018-03-24
    • 2021-03-18
    • 1970-01-01
    相关资源
    最近更新 更多