JackMcKew / pyinstaller-action-linux

Github Action for building executables with Pyinstaller for Linux
MIT License
28 stars 21 forks source link

Not loading tkinter module #2

Closed ThePieBandit closed 4 years ago

ThePieBandit commented 4 years ago

Describe the bug I have a python script that uses tkinter to provide a simple file dialog and message box. When I test and build locally with pyinstaller to generate the spec file, the executable works fine. building in the github action succeeds, but the executable created doesn't work, giving the error:

Traceback (most recent call last):
  File "tcg-to-deckbox.py", line 6, in <module>
  File "/root/.pyenv/versions/3.7.5/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
  File "tkinter/__init__.py", line 36, in <module>
ModuleNotFoundError: No module named '_tkinter'

To Reproduce I ran with the following github action flow


# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
# additionally allows a manual trigger via workflow_dispatch
on:
  workflow_dispatch:
    types: ManualUpdate
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
    # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - uses: actions/checkout@v2

    - name: PyInstaller Linux
      uses: JackMcKew/pyinstaller-action-linux@0.1.3
      with:
        path: src

    - uses: actions/upload-artifact@v2
      with:
        name: tcg-to-deckbox
        path: src/dist/linux

successful.log failure_logs_17.zip

As you'll note from the attached logs, the one where the executable functions has the line 3120 INFO: Loading module hook 'hook-_tkinter.py' from '/home/rspremulli/.local/lib/python3.6/site-packages/PyInstaller/hooks'... while the github action doesn't. Is there some issue why it won't load the tkinter module?

JackMcKew commented 4 years ago

Could you please share your .spec file. I have a suspicion that it may need to be specified in the .spec file exactly where to look for _tkinter in the analysis tree, likein the documentation here: https://pyinstaller.readthedocs.io/en/stable/spec-files.html.

PS, to confirm, this executable is intended to run on Linux yes?

ThePieBandit commented 4 years ago

Spec file is available here, as is my project: https://github.com/ThePieBandit/TCG-to-Deckbox/blob/releaseActions/src/tcg-to-deckbox.spec. I've tried entering tkinter and _tkinter to no effect

I am trying to run this on linux, eventually I plan on using your other repo to have a github action create a windows executable as well

ThePieBandit commented 4 years ago

My understanding is that tkinter is supposed to be a built in python module, but admittedly I'm pretty new at python.

JackMcKew commented 4 years ago

This was a real doozy in the end!

Turns out that Linux doesn't have the binaries for Tkinter by default, and thus you must install them before installing Python.

I've added an argument now that will uninstall Python, install the Tkinter binaries, and install Python again if the user has specified tkinter to be true in their action.yml. This can be seen in release 0.1.4 https://github.com/JackMcKew/pyinstaller-action-linux/releases/tag/0.1.4.

I forked your example repo until I got it working, for which you can see it successfully packaging here: https://github.com/JackMcKew/TCG-to-Deckbox/actions/runs/229445716

I don't have a linux machine ready at the moment, so it is unverified whether the application works as intended.

I hope this has fixed the issue for you, and I'm unsure whether the Windows pyinstaller action will behave similarly, but please raise an issue if it does.

ThePieBandit commented 4 years ago

Unfortunately, it still isn't working. I can see your github action doing more things like installing tk, but I still don't see pyinstaller picking it up.

https://github.com/ThePieBandit/TCG-to-Deckbox/actions/runs/229650750

JackMcKew commented 4 years ago

Ah thank you for raising this again. The error was due to .bashrc not being sourced correctly and the Github Action user not being able to access Pyenv to recompile Python after Tkinter was installed.

I have now fixed this as you can see in this runtime (https://github.com/JackMcKew/TCG-to-Deckbox/runs/1044598608?check_suite_focus=true), note the line within the Pyinstaller Linux step:

4073 INFO: Loading module hook 'hook-_tkinter.py' from '/root/.pyenv/versions/3.7.5/lib/python3.7/site-packages/PyInstaller/hooks'...

Since this dramatically slows down the action (from uninstalling Python, install Tkinter and recompiling Python), I've decided to leave this on a separate branch of the action. This can be used by specifying the tkinter branch (eg JackMcKew/pyinstaller-action-linux@tkinter).

Note that I still cannot 100% test that this is fully working on a linux machine, but I believe this is a step in the right direction. Please close the issue if this has solved this problem for you 👍

PS, I also tested on the Windows pyinstaller action which did not have this amount of trouble, please find the logs: https://github.com/JackMcKew/TCG-to-Deckbox/runs/1044515031?check_suite_focus=truehttps://github.com/JackMcKew/TCG-to-Deckbox/runs/1044515031?check_suite_focus=true

ThePieBandit commented 4 years ago

Looks like it works! I tested the app you built and no errors are raised.

JackMcKew commented 4 years ago

Fantastic! Thank you for raising this