前提・実現したいこと
海外のQtを使用したMP4プレイヤーのサンプルコードを
pyinstallerでexe化しようとしたところ、成功はするのですが
いくつかエラーが発生し、作成されたEXEファイルも起動しません
どうすればよいでしょうか?
発生している問題・エラーメッセージ
エラーメッセージ
Python path configuration: PYTHONHOME = 'C:\Workspeac\dist\player' PYTHONPATH = (not set) program name = 'C:\Workspeac\dist\player\player.exe' isolated = 0 environment = 0 user site = 0 import site = 0 sys._base_executable = 'C:\Workspeac\dist\player\player.exe' sys.base_prefix = '' sys.base_exec_prefix = '' sys.platlibdir = 'lib' sys.executable = 'C:\Workspeac\dist\player\player.exe' sys.prefix = '' sys.exec_prefix = '' sys.path = [ 'C:\Workspeac\dist\player\base_library.zip', 'C:\Workspeac\dist\player\lib-dynload', 'C:\Workspeac\dist\player', ] Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding Python runtime state: core initialized ModuleNotFoundError: No module named 'encodings' Current thread 0x00004f6c (most recent call first): <no Python frame>
トレースバック
Traceback
1 File "c:\users\my_username\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main 2 return _run_code(code, main_globals, None, 3 File "c:\users\my_username\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code 4 exec(code, run_globals) 5 File "C:\Users\my_username\AppData\Local\Programs\Python\Python39\Scripts\pyinstaller.exe\__main__.py", line 7, in <module> 6 File "c:\users\my_username\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\__main__.py", line 114, in run 7 run_build(pyi_config, spec_file, **vars(args)) 8 File "c:\users\my_username\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build 9 PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) 10 File "c:\users\my_username\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\build_main.py", line 737, in main 11 build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build')) 12 File "c:\users\my_username\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\build_main.py", line 684, in build 13 exec(code, spec_namespace) 14 File "C:\Workspeac\player.spec", line 31, in <module> 15 coll = COLLECT(exe, 16 File "c:\users\my_username\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\api.py", line 712, in __init__ 17 self.__postinit__() 18 File "c:\users\my_username\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__ 19 self.assemble() 20 File "c:\users\my_username\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\api.py", line 756, in assemble 21 shutil.copy(fnm, tofnm) 22 File "c:\users\my_username\appdata\local\programs\python\python39\lib\shutil.py", line 418, in copy 23 copyfile(src, dst, follow_symlinks=follow_symlinks) 24 File "c:\users\my_username\appdata\local\programs\python\python39\lib\shutil.py", line 264, in copyfile 25 with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst: 26FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\my_username\AppData\Local\pyinstaller\bincache00_py39_64bit\pyqt5\qt\plugins\platforms\qminimal.dll'
該当のソースコード
python
1import sys 2from functools import partial 3from PyQt5.QtCore import QEvent, QUrl, Qt 4from PyQt5.QtWidgets import (QApplication, QHBoxLayout, QMainWindow, 5 QWidget, QPushButton, QSlider, 6 QVBoxLayout) 7from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer 8from PyQt5.QtMultimediaWidgets import QVideoWidget 9# Ruta del archivo. 10VIDEO_PATH = "Profire.avi" 11class MainWindow(QMainWindow): 12 13 def __init__(self): 14 super().__init__() 15 16 # Controles principales para organizar la ventana. 17 self.widget = QWidget(self) 18 self.layout = QVBoxLayout() 19 self.bottom_layout = QHBoxLayout() 20 21 # Control de reproducción de video de Qt. 22 self.video_widget = QVideoWidget(self) 23 self.media_player = QMediaPlayer() 24 self.media_player.setMedia( 25 QMediaContent(QUrl.fromLocalFile(VIDEO_PATH))) 26 self.media_player.setVideoOutput(self.video_widget) 27 28 # Botones de reproducción y pausa. 29 self.play_button = QPushButton("PAUSE", self) 30 self.stop_button = QPushButton("最初から", self) 31 32 # Deslizadores para el volumen y transición del video. 33 self.seek_slider = QSlider(Qt.Horizontal) 34 self.volume_slider = QSlider(Qt.Horizontal) 35 self.volume_slider.setRange(0, 100) 36 self.volume_slider.setValue(self.media_player.volume()) 37 self.seek_slider.sliderMoved.connect(self.media_player.setPosition) 38 self.volume_slider.sliderMoved.connect(self.media_player.setVolume) 39 self.media_player.positionChanged.connect(self.seek_slider.setValue) 40 self.media_player.durationChanged.connect( 41 partial(self.seek_slider.setRange, 0)) 42 43 # Acomodar controles en la pantalla. 44 self.layout.addWidget(self.video_widget) 45 self.layout.addLayout(self.bottom_layout) 46 self.bottom_layout.addWidget(self.play_button) 47 self.bottom_layout.addWidget(self.stop_button) 48 self.bottom_layout.addWidget(self.volume_slider) 49 self.layout.addWidget(self.seek_slider) 50 51 # Conectar los eventos con sus correspondientes funciones. 52 self.play_button.clicked.connect(self.play_clicked) 53 self.stop_button.clicked.connect(self.stop_clicked) 54 self.media_player.stateChanged.connect(self.state_changed) 55 56 # Se utiliza installEventFilter() para capturar eventos 57 # del mouse en el control de video. 58 self.video_widget.installEventFilter(self) 59 60 # Personalizar la ventana. 61 self.setWindowTitle("ゆるキャン△ Season1 一話") 62 self.resize(800, 600) 63 self.layout.setContentsMargins(0, 0, 0, 0) 64 self.bottom_layout.setContentsMargins(0, 0, 0, 0) 65 self.widget.setLayout(self.layout) 66 self.setCentralWidget(self.widget) 67 68 # Reproducir el video. 69 self.media_player.play() 70 71 def play_clicked(self): 72 """ 73 Comenzar o resumir la reproducción. 74 """ 75 if (self.media_player.state() in 76 (QMediaPlayer.PausedState, QMediaPlayer.StoppedState)): 77 self.media_player.play() 78 else: 79 self.media_player.pause() 80 81 def stop_clicked(self): 82 """ 83 Detener la reproducción. 84 """ 85 self.media_player.stop() 86 87 def state_changed(self, newstate): 88 """ 89 Actualizar el texto de los botones de reproducción y pausa. 90 """ 91 states = { 92 QMediaPlayer.PausedState: "再生", 93 QMediaPlayer.PlayingState: "一時停止", 94 QMediaPlayer.StoppedState: "再生する" 95 } 96 self.play_button.setText(states[newstate]) 97 self.stop_button.setEnabled(newstate != QMediaPlayer.StoppedState) 98 99 def eventFilter(self, obj, event): 100 """ 101 Establecer o remover pantalla completa al obtener 102 el evento MouseButtonDblClick. 103 """ 104 if event.type() == QEvent.MouseButtonDblClick: 105 obj.setFullScreen(not obj.isFullScreen()) 106 return False 107if __name__ == "__main__": 108 app = QApplication(sys.argv) 109 window = MainWindow() 110 window.show() 111 sys.exit(app.exec_())
試したこと
Pyqtの再インストールや無いと言われたdllを直接追加してみたのですが
私の知識やGoogle検索ではどうにもうまくいかなくて質問させていただきました
あなたの回答
tips
プレビュー