前提・やりたいこと
moviepyで動画から音声を取り出したい。
問題・エラーコード
python
1ModuleNotFoundError: No module named 'moviepy.editor'; 'moviepy' is not a package
上記のエラーが発生する
該当のコード
python
1# MoviPy ライブラリを使う準備 2import moviepy.editor as mp 3 4# 動画ファイルを加工する準備 5clip = mp.VideoFileClip("ouji.mp4") 6 7# 動画から音声を抜き出して音声ファイルを保存 8clip.audio.write_audiofile("audio.wav")
「ouji.mp4」が音声を取り出したい動画ファイルの名前です。
結果↓
python
1Traceback (most recent call last): 2 File "/Users/takeru/Desktop/moviepy.py", line 2, in <module> 3 import moviepy.editor as mp 4 File "/Users/takeru/Desktop/moviepy.py", line 2, in <module> 5 import moviepy.editor as mp 6ModuleNotFoundError: No module named 'moviepy.editor'; 'moviepy' is not a package
試したこと
moviepyのインストール
気になる質問をクリップする
クリップした質問は、後からいつでもMYページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
回答1件
0
実行するファイルをmoviepy.py
という名前で保存すると、import moviepy
文でインポートされるモジュールはそのファイル自身になってしまいます。
標準ライブラリやインストールしたモジュールと同じ名前でファイルを作ってはダメです。
投稿2022/03/07 13:38
総合スコア11299
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
回答ありがとうございます。
ファイルの名前を変更したら解消しましたが、新しいエラーが出てしまいました。。。
Traceback (most recent call last):
File "/Users/takeru/Desktop/動画.py", line 2, in <module>
import moviepy.editor as mp
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/moviepy/editor.py", line 36, in <module>
from .video.io.VideoFileClip import VideoFileClip
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/moviepy/video/io/VideoFileClip.py", line 3, in <module>
from moviepy.audio.io.AudioFileClip import AudioFileClip
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/moviepy/audio/io/AudioFileClip.py", line 3, in <module>
from moviepy.audio.AudioClip import AudioClip
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/moviepy/audio/AudioClip.py", line 7, in <module>
from moviepy.audio.io.ffmpeg_audiowriter import ffmpeg_audiowrite
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/moviepy/audio/io/ffmpeg_audiowriter.py", line 7, in <module>
from moviepy.config import get_setting
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/moviepy/config.py", line 36, in <module>
FFMPEG_BINARY = get_exe()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/imageio/plugins/ffmpeg.py", line 159, in get_exe
return imageio_ffmpeg.get_ffmpeg_exe()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/imageio_ffmpeg/_utils.py", line 49, in get_ffmpeg_exe
raise RuntimeError(
RuntimeError: No ffmpeg exe could be found. Install ffmpeg on your system, or set the IMAGEIO_FFMPEG_EXE environment variable.
もし何か分かるようでしたら回答いただけると嬉しいです。
No ffmpeg exe could be found. Install ffmpeg on your system, or set the IMAGEIO_FFMPEG_EXE environment variable.
と書いてあるとおりかと。
pip list
Package Version
------------------ ---------
certifi 2021.10.8
charset-normalizer 2.0.12
decorator 4.4.2
ffmpeg-python 0.2.0
future 0.18.2
idna 3.3
imageio 2.16.1
imageio-ffmpeg 0.4.5
moviepy 1.0.3
numpy 1.22.2
Pillow 9.0.1
pip 22.0.4
proglog 0.1.9
requests 2.27.1
setuptools 60.5.0
tqdm 4.63.0
urllib3 1.26.8
wheel 0.37.1
ここで見るとあるんですよね
pipでffmpegが入るわけじゃないでしょう。
ffmpegコマンドが実行できる状態が必要なんだと思います。
(moviepyのことは何も知りませんがメッセージを読むとそうなんだろうな、という話です)
https://github.com/imageio/imageio-ffmpeg/blob/master/imageio_ffmpeg/_utils.py#L87
ここですね。ffmpegでコマンド実行できるか確認してます。
macだったらHomebrewで
brew install ffmpeg
とインストールするのが簡単なんでしょうかね。
brew install ffmpeg
Running `brew update --preinstall`...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
aws-auth mu-repo spidermonkey@78
==> Updated Formulae
Updated 120 formulae.
==> New Casks
poker-copilot
==> Updated Casks
Updated 60 casks.
==> Deleted Casks
pd-runner
Warning: ffmpeg 5.0 is already installed and up-to-date.
To reinstall 5.0, run:
brew reinstall ffmpeg
上記のようにbrew install ffmpeg とやってみたのですが、いまだにエラーが出てしまいます。。。
何度もすみませんm(_ _)m
コードを見た感じ **コマンドラインから ffmpeg -version と打って起動できるなら** 大丈夫に見えますが……なにが起きてるんでしょう??
ffmpeg version 5.0 Copyright (c) 2000-2022 the FFmpeg developers
built with Apple clang version 13.0.0 (clang-1300.0.29.30)
configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/5.0 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-neon
libavutil 57. 17.100 / 57. 17.100
libavcodec 59. 18.100 / 59. 18.100
libavformat 59. 16.100 / 59. 16.100
libavdevice 59. 4.100 / 59. 4.100
libavfilter 8. 24.100 / 8. 24.100
libswscale 6. 4.100 / 6. 4.100
libswresample 4. 3.100 / 4. 3.100
libpostproc 56. 3.100 / 56. 3.100
パソコンにffmpegは入ってると思います。
パスというものを設定する必要があるのでしょうか。。。
思いつく原因はもうないですね……。この状態だとそのエラーにはならないはず、と思ってしまいます
RuntimeError: No ffmpeg exe could be found. Install ffmpeg on your system, or set the IMAGEIO_FFMPEG_EXE environment variable.
同じエラーが出てしまうんですよね、、
IMAGEIO_FFMPEG_EXE これの環境を整えなきゃいけないということなのでしょうか。
トライしてみてもいいとは思います
(それで動いても subprocess.check_call が失敗する理由の想像ができませんけれど)
ffmpeg 自体がおかしんですかね、、
「ffmpeg -version が実行できること」しかチェックしてないと思うので
それを確認してみますか。
ffmpeg -version
echo $?
で 0 が印字されますか?
参考 https://shellscript.sunone.me/exit_status.html
ffmpeg -version echo $?
ffmpeg version 5.0 Copyright (c) 2000-2022 the FFmpeg developers
built with Apple clang version 13.0.0 (clang-1300.0.29.30)
configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/5.0 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-neon
libavutil 57. 17.100 / 57. 17.100
libavcodec 59. 18.100 / 59. 18.100
libavformat 59. 16.100 / 59. 16.100
libavdevice 59. 4.100 / 59. 4.100
libavfilter 8. 24.100 / 8. 24.100
libswscale 6. 4.100 / 6. 4.100
libswresample 4. 3.100 / 4. 3.100
libpostproc 56. 3.100 / 56. 3.100
これでいいでしょうか、、?
多分コマンドを正しく書けてませんよね。。。
echo $?
0
印字されました!

あなたの回答
tips
太字
斜体
打ち消し線
見出し
引用テキストの挿入
コードの挿入
リンクの挿入
リストの挿入
番号リストの挿入
表の挿入
水平線の挿入
プレビュー
質問の解決につながる回答をしましょう。 サンプルコードなど、より具体的な説明があると質問者の理解の助けになります。 また、読む側のことを考えた、分かりやすい文章を心がけましょう。