Cahan uuu
Cahan uuu

Reputation: 61

Moviepy module error when converting to exe with pyinstaller

After packing with pyinstaller py file I get the following error:

Traceback (most recent call last):
 File "gui.py", line 10, 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", line540, 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'
[8028] Failed to execute script gui

I didn't use anything called audio in my code, there is only a code that converts mp4 to mp3.

This is the code:

mp4_file = os.path.abspath(os.getcwd()) + "\\Files\\Mp3\\Mp3_Temp_File\\Temp_video.mp4"
mp3_file = os.path.abspath(os.getcwd()) + "\\Files\\Mp3\\" + str(yt.title) + ".mp3"
videoclip = VideoFileClip(mp4_file)
audioclip = videoclip.audio
audioclip.write_audiofile(mp3_file)
audioclip.close()
videoclip.close() 

How can I fix this error? I tried using different pyinstaller codes but got nothing

Upvotes: 1

Views: 852

Answers (1)

The Reider
The Reider

Reputation: 163

I have the exact same code and same error.

Here is my solution:

  1. You use the pyinstaller to convert it to an exe pyinstaller myfile.py(i know the exe doesnt work).
  2. If you generate the exe, pyinstaller add a .spec file with the same name as the python script (For example: "myfile.spec").
  3. You must edit the .spec file (You can do this with Notepad++) and add the line a.datas += Tree("moviepypath", prefix='moviepy') like I did:
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(
...)

a.datas += Tree("moviepypath", prefix='moviepy')
...

You have to put the moviepy path instead of "moviepypath" in it(Dont forget the "" at the begin and end of the path). If you dont know the path of moviepy, than press windows + r and type in the window %appdata%, scroll down to the folder "Python", go to "site-packages" and copy the path of moviepy. Now it should works.

Upvotes: 2

Related Questions