abdeladim-s / subsai

🎞️ Subtitles generation tool (Web-UI + CLI + Python package) powered by OpenAI's Whisper and its variants 🎞️
https://abdeladim-s.github.io/subsai/
GNU General Public License v3.0
1.25k stars 104 forks source link

Cant create .exe with PyInstaller when Subsai is imported #39

Open farzadnk opened 1 year ago

farzadnk commented 1 year ago

I am trying to create a small program that works with Subsai. I then build the Python script to the .exe file using PyInstaller (auto-py-to-exe). When I run the .exe file, I get the following error:

File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\auto_py_to_exe\packaging.py", line 131, in package run_pyinstaller() File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\__main__.py", line 180, in run run_build(pyi_config, spec_file, **vars(args)) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\__main__.py", line 61, in run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\building\build_main.py", line 1035, in main build(specfile, distpath, workpath, clean_build) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\building\build_main.py", line 957, in build exec(code, spec_namespace) File "C:\Users\FARZAD~1\AppData\Local\Temp\tmpbkihmg4b\main.spec", line 21, in <module> a = Analysis( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\building\build_main.py", line 442, in __init__ self.__postinit__() File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\building\datastruct.py", line 184, in __postinit__ self.assemble() File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\building\build_main.py", line 603, in assemble priority_scripts.append(self.graph.add_script(script)) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 268, in add_script self._top_script_node = super().add_script(pathname) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1359, in add_script self._process_imports(n) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2811, in _process_imports target_modules = self._safe_import_hook(*import_info, **kwargs) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 432, in _safe_import_hook return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2262, in _safe_import_hook target_modules = self.import_hook( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1431, in import_hook target_package, target_module_partname = self._find_head_package( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1610, in _find_head_package target_package = self._safe_import_module( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 479, in _safe_import_module return super()._safe_import_module(module_basename, module_name, parent_package) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1992, in _safe_import_module self._process_imports(n) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2811, in _process_imports target_modules = self._safe_import_hook(*import_info, **kwargs) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 432, in _safe_import_hook return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2262, in _safe_import_hook target_modules = self.import_hook( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1444, in import_hook submodule = self._safe_import_module(head, mname, submodule) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 479, in _safe_import_module return super()._safe_import_module(module_basename, module_name, parent_package) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1992, in _safe_import_module self._process_imports(n) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2811, in _process_imports target_modules = self._safe_import_hook(*import_info, **kwargs) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 432, in _safe_import_hook return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2262, in _safe_import_hook target_modules = self.import_hook( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1444, in import_hook submodule = self._safe_import_module(head, mname, submodule) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 479, in _safe_import_module return super()._safe_import_module(module_basename, module_name, parent_package) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1992, in _safe_import_module self._process_imports(n) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2811, in _process_imports target_modules = self._safe_import_hook(*import_info, **kwargs) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 432, in _safe_import_hook return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2262, in _safe_import_hook target_modules = self.import_hook( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1431, in import_hook target_package, target_module_partname = self._find_head_package( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1610, in _find_head_package target_package = self._safe_import_module( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 479, in _safe_import_module return super()._safe_import_module(module_basename, module_name, parent_package) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1992, in _safe_import_module self._process_imports(n) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2811, in _process_imports target_modules = self._safe_import_hook(*import_info, **kwargs) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 432, in _safe_import_hook return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2262, in _safe_import_hook target_modules = self.import_hook( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1431, in import_hook target_package, target_module_partname = self._find_head_package( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1610, in _find_head_package target_package = self._safe_import_module( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 479, in _safe_import_module return super()._safe_import_module(module_basename, module_name, parent_package) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1992, in _safe_import_module self._process_imports(n) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2811, in _process_imports target_modules = self._safe_import_hook(*import_info, **kwargs) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 432, in _safe_import_hook return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2262, in _safe_import_hook target_modules = self.import_hook( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1444, in import_hook submodule = self._safe_import_module(head, mname, submodule) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 479, in _safe_import_module return super()._safe_import_module(module_basename, module_name, parent_package) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1992, in _safe_import_module self._process_imports(n) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2811, in _process_imports target_modules = self._safe_import_hook(*import_info, **kwargs) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 432, in _safe_import_hook return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2262, in _safe_import_hook target_modules = self.import_hook( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1431, in import_hook target_package, target_module_partname = self._find_head_package( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1610, in _find_head_package target_package = self._safe_import_module( File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 479, in _safe_import_module return super()._safe_import_module(module_basename, module_name, parent_package) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1992, in _safe_import_module self._process_imports(n) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2811, in _process_imports target_modules = self._safe_import_hook(*import_info, **kwargs) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 368, in _safe_import_hook excluded_imports = self._find_all_excluded_imports(source_module.identifier) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line 356, in _find_all_excluded_imports excluded_imports.update(module_hook.excludedimports) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\imphook.py", line 316, in __getattr__ self._load_hook_module() File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\imphook.py", line 383, in _load_hook_module self._hook_module = importlib_load_source(self.hook_module_name, self.hook_filename) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\compat.py", line 612, in importlib_load_source return mod_loader.load_module() File "<frozen importlib._bootstrap_external>", line 529, in _check_name_wrapper File "<frozen importlib._bootstrap_external>", line 1029, in load_module File "<frozen importlib._bootstrap_external>", line 854, in load_module File "<frozen importlib._bootstrap>", line 274, in _load_module_shim File "<frozen importlib._bootstrap>", line 711, in _load File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 850, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-webrtcvad.py", line 15, in <module> datas = copy_metadata('webrtcvad') File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\PyInstaller\utils\hooks\__init__.py", line 942, in copy_metadata dist = pkg_resources.get_distribution(package_name) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\pkg_resources\__init__.py", line 477, in get_distribution dist = get_provider(dist) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\pkg_resources\__init__.py", line 353, in get_provider return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0] File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\pkg_resources\__init__.py", line 897, in require needed = self.resolve(parse_requirements(requirements)) File "C:\Users\Farzad Nikzad\AppData\Roaming\Python\Python39\site-packages\pkg_resources\__init__.py", line 783, in resolve raise DistributionNotFound(req, requirers) pkg_resources.DistributionNotFound: The 'webrtcvad' distribution was not found and is required by the application

And this is the part of my code in which subsai are used, and when I delete this part, the exe file is created without any problem.

` def create_subtitles(self):

    if not self.input_dir or not self.output_dir or not self.audio_dir:
        messagebox.showerror("Error", "Please select input, output, and audio directories.")
        return

    subs_ai = SubsAI()
    model_type = self.model_type_var.get()
    model = WhisperTimeStamped({'model_type': model_type})
    model = WhisperTimeStamped({"segment_type": "word"})

    for filename in os.listdir(self.input_dir):
        if filename.endswith('.mp4') or filename.endswith('.avi'):

            video_path = os.path.join(self.input_dir, filename)
            subtitle_path = os.path.join(self.output_dir, filename[:-4] + '.ass')
            audio_path = os.path.join(self.audio_dir, filename[:-4] + '.mp3')

            subprocess.run(['ffmpeg', '-i', video_path, '-vn', '-acodec', 'libmp3lame', '-q:a', '2', audio_path])

            subs = subs_ai.transcribe(audio_path, model)
            subs.save(subtitle_path)
    `
abdeladim-s commented 1 year ago

It seems like the problem is originating from webrtcvad. Try to remove pywhispercpp and see.

Note also that to generate an exe file with PyInstaller is not an easy task, the models depend on Pytorch and it is hard and heavy to package.