通过 PyInstaller 创建的可执行文件崩溃
Executable created via PyInstaller crashes
我创建了一个小应用程序来下载 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
创建 exe 时使用隐藏导入
pyinstaller --hidden-import=pkg_resources.py2_warn --onefile -c test.py
我创建了一个小应用程序来下载 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
创建 exe 时使用隐藏导入
pyinstaller --hidden-import=pkg_resources.py2_warn --onefile -c test.py