Python 通过PyInstaller创建的可执行文件崩溃

Python 通过PyInstaller创建的可执行文件崩溃,python,pyinstaller,Python,Pyinstaller,我创建了一个小应用程序来下载youtube视频,并将它们添加到我的音乐文件夹中,这样我就可以通过spotify收听它们。只要我通过IDE运行该应用程序,它就可以正常工作。 我通过pyinstaller创建了一个.exe文件,但它在启动时崩溃了,我尝试以管理员身份运行它,也尝试按照其他线程中的建议通过cmd运行它,但没有任何效果 我使用以下方法创建了它: pyinstaller --onefile -c test.py 这是python代码: from pytube import YouTube

我创建了一个小应用程序来下载youtube视频,并将它们添加到我的音乐文件夹中,这样我就可以通过spotify收听它们。只要我通过IDE运行该应用程序,它就可以正常工作。 我通过pyinstaller创建了一个.exe文件,但它在启动时崩溃了,我尝试以管理员身份运行它,也尝试按照其他线程中的建议通过cmd运行它,但没有任何效果

我使用以下方法创建了它:

pyinstaller --onefile -c test.py
这是python代码:

from pytube import YouTube
from pytube import Playlist
from moviepy.editor import *
from pathlib import Path
import os

url = input('Enter URL: ')
ytd = YouTube(url)
stream = ytd.streams.first().download(filename= 'video') #stiahne do root filu
mp3_file = ytd.title + '.mp3' #meno pesnicky
#videoClip = VideoFileClip('video.mp4')
audioClip = VideoFileClip('video.mp4').audio
audioClip.write_audiofile(mp3_file) #mp4 na mp3
audioClip.close()
VideoFileClip('video.mp4').close() #v root file je mp3 a mp4
os.remove('video.mp4') #zmaze mp4, ostane mp3
file_path = str(os.path.dirname(os.path.realpath(mp3_file))) + '\\' + mp3_file
music_path = str(os.path.join(Path.home(), "Music")) + '\\' + mp3_file
Path(file_path).rename(music_path)
这是我得到的,我尝试通过cmd运行它:

Traceback (most recent call last):
  File "C:\Users\rporu\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\PyInstaller\loader\rthooks\pyi_rth_pkgres.py", line 13, in <module>
    import pkg_resources as res
  File "c:\users\rporu\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\pkg_resources\__init__.py", line 86, in <module>
ModuleNotFoundError: No module named 'pkg_resources.py2_warn'
[3296] Failed to execute script pyi_rth_pkgres
回溯(最近一次呼叫最后一次):
文件“C:\Users\rporu\AppData\Local\Programs\Python\Python38-32\Lib\site packages\PyInstaller\loader\rthooks\pyi\rth\u pkgres.py”,第13行,在
将pkg_资源作为资源导入
exec_模块中的文件“c:\users\rporu\appdata\local\programs\python38-32\lib\site packages\PyInstaller\loader\pyimod03_importers.py”,第623行
exec(字节码、模块、指令)
文件“site packages\pkg\u resources\\uuuuu init\uuuuuu.py”,第86行,在
ModuleNotFoundError:没有名为'pkg_resources.py2_warn'的模块
[3296]无法执行脚本pyi_rth_pkgres

创建exe时使用隐藏导入

pyinstaller --hidden-import=pkg_resources.py2_warn --onefile -c test.py

它仍然会立即关闭:AttributeError:module'moviepy.audio.fx.all'has no attribute'audio_fadein'这是一个不同的错误,前一个已经解决。更改导入语句“from moviepy.video.io.VideoFileClip import VideoFileClip”如下选中此处请将答案标记为已解决,新错误是否已修复?