0

I'm trying to create an executable from a Python code I wrote using PyQt5 and just can't get it to work. I've been following this: https://blog.aaronhktan.com/posts/2018/05/14/pyqt5-pyinstaller-executable example when it comes to adding the images and added all the PyQt5 things to the hidden imports of the spec file but nothing seems to work.

When this is created on my desktop I developed the code in, everything works and is fine. The image shows up and it runs right from the dist folder. But when I email the exe to my laptop and open it open I get the "Failed to execute script abra_teleport". I'm just not sure what it doesn't like.

EDIT: I changed the code to that instead of from PyQt5.QtWidgets import * it has from PyQt5.QtWidgets import QLabel, QPushButton, QApplication, QMainWindow but that doesn't change anything.

Code:

import sys
import os
import PyQt5
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

class Abra(QMainWindow):
    def __init__(self):
        super().__init__()
        self.title='I choose you! Abra!'
        self.left=100
        self.top=100
        self.width=320
        self.height=200
        self.window()

    def window(self):
        def resource_path(relative_path):
            if hasattr(sys, '_MEIPASS'):
                return os.path.join(sys._MEIPASS, relative_path)
            return os.path.join(os.path.abspath('.'), relative_path)
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        self.label=QLabel('',self)
        self.label.move(100,20)
        self.abra=QLabel(self)
        self.abra.setPixmap(QPixmap(resource_path('resources/sprites/abra.png')))
        self.abra.move(130, 90)
        self.button=QPushButton('Go Abra!',self)
        self.button.move(110,150)
        self.button.clicked.connect(self.on_click)
        self.show()


    def part1(self):
        def resource_path(relative_path):
            if hasattr(sys, '_MEIPASS'):
                return os.path.join(sys._MEIPASS, relative_path)
            return os.path.join(os.path.abspath('.'), relative_path)
        try:
            self.label.setText('')
            self.abra.setPixmap(QPixmap(resource_path('resources/sprites/abra.png')))
            self.button.setText('Go Abra!')
            self.button.clicked.connect(self.on_click)
        except:
            print('mmm')

    def on_click(self):
        try:
            self.label.setText('Abra used Teleport!')
            self.label.adjustSize()
            self.abra.setPixmap(QPixmap(''))
            self.button.setText('Try again!')
            self.button.clicked.connect(self.part1)
        except:
            print('nope')

if __name__=='__main__':
    app=QApplication(sys.argv)
    ex=Abra()
    ex.show()
    sys.exit(app.exec_())

Spec File:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['abra_teleport.py'],
             pathex=['C:\\Users\\marina\\Documents\\PokemonGUIProject\\Tests'],
             binaries=[],
             datas=[],
             hiddenimports=['PyQt5','PyQt5.QtWidgets','PyQt5.QtGui','PyQt5.QtCore'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)

a.datas += [('resources/sprites/abra.png','resources/sprites/abra.png','DATA')]

pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)

exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='abra_teleport',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          runtime_tmpdir=None,
          console=False )
  • Use dependencywalker to see if you are missing dlls, then look for them on your PC and copy them next to the executable. – eyllanesc Nov 02 '19 at 20:30
  • Try to enable console mode with setting `console=True`, `debug=True` in the spec file and rerun the app, then put the full error log in here. – Masoud Rahimi Nov 03 '19 at 04:17

0 Answers0