Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Executable build with PyInstaller #23

Closed
cutright opened this issue Jan 4, 2020 · 8 comments
Closed

Executable build with PyInstaller #23

cutright opened this issue Jan 4, 2020 · 8 comments

Comments

@cutright
Copy link
Owner

cutright commented Jan 4, 2020

I'm adding this partially to help me remember what I've done, and partially in hopes that someone with more experience out there might be able to help.

I think I have successfully compiled DVHA for macOS Mojave. You can give this a try by downloading DVHA_macOS_Mojave.zip on the releases page - or directly download with this hard link to 0.6.3 (+ minor fixes) here. Your browser may automatically unzip this file which contains a single app, double click to run. You may need to enable this app in System Preferences -> Security & Privacy -> Open Anyway.

Screen Shot 2020-01-04 at 10 09 36 AM

Screen Shot 2020-01-04 at 10 05 57 AM

Here is the Pyinstaller spec file I used:

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['dvha_app.py'],
             pathex=['./',
                     './venv/lib/python3.6/site-packages'],
             binaries=[('/System/Library/Frameworks/Tk.framework/Tk', 'tk'),
                       ('/System/Library/Frameworks/Tcl.framework/Tcl', 'tcl')],
             datas=[('./dvha/icons/', './dvha/icons/'),
                    ('./dvha/logo.png', './dvha/'),
                    ('./dvha/LICENSE', './dvha/'),
                    ('./dvha/db/create_tables.sql', './dvha/db/'),
                    ('./dvha/db/institutional.roi', './dvha/db/'),
                    ('./dvha/db/physician_BBM.roi', './dvha/db/')],
             hiddenimports=['sklearn.utils._cython_blas',
                            'sklearn.neighbors._typedefs',
                            'sklearn.neighbors._quad_tree',
                            'sklearn.tree._utils'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='dvha_app',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=False,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=False)
app = BUNDLE(exe,
             name='DVH Analytics',
             icon='./dvha/icon.jpg',
             bundle_identifier=None,
             info_plist={'NSHighResolutionCapable': 'True'}
             )

For MS Windows, I've successfully packaged an executable that works on my PC, but no one else's... so I suspect there's some more dll files I'm missing. I also ran into issues with SciPy because it moved its dll files, but I got around this by downgrading SciPy by one version. I'll post my MSW spec file on Monday (I left it at work).

@mchamberland
Copy link

For what it's worth, the Mac version runs on Catalina, too. But I don't have a database set up on my laptop or plan files to test it with.

@cutright
Copy link
Owner Author

cutright commented Jan 6, 2020

Here is my .spec file for MS Windows. Successful compilation on my PC with Windows 7 Enterprise Service Pack 1. Intel Core i5. I couldn't catch the text of the terminal because I can't get it to stay open, but below is a screen shot of the ouput.

Looks like PyInstaller is saving some absolute paths instead of relative?

# -*- mode: python ; coding: utf-8 -*-

# Windows fails with scipy >= 1.3.0  (needs the extra-dll folder in package)

block_cipher = None


a = Analysis(['dvha_app.py'],
             pathex=[r".",
                     r".\venv\Lib\site-packages"],
             binaries=[],
             datas=[(r".\dvha\icons", r".\dvha\icons"),
                    (r".\dvha\logo.png", r".\dvha"),
                    (r".\dvha\LICENSE", r".\dvha"),
                    (r".\dvha\db\create_tables.sql", r".\dvha\db"),
                    (r".\dvha\db\institutional.roi", r".\dvha\db"),
                    (r".\dvha\db\physician_BBM.roi", r".\dvha\db")],
             hiddenimports=['sklearn.utils._cython_blas',
                            'sklearn.neighbors._typedefs',
                            'sklearn.neighbors._quad_tree',
                            'sklearn.tree._utils'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='dvha_app',
          debug=True,
          bootloader_ignore_signals=False,
          strip=False,
          upx=False,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True)
app = BUNDLE(exe,
             name='DVH Analytics',
             icon=r".\dvha.ico",
             bundle_identifier=None,
             info_plist={'NSHighResolutionCapable': 'True'}
             )

image

@cutright
Copy link
Owner Author

cutright commented Jan 6, 2020

I since added my venv to datas, still getting an error.

@mchamberland I wonder if the uploaded binary only worked on your mac because you already had the appropriate python libraries installed?

image

@cutright cutright added this to the v1.0 milestone Jan 14, 2020
@cutright
Copy link
Owner Author

Success!! Will try to post an executable tomorrow along with a version update.

I should have read the output more closely. The issue is sklearn.

I edited sklearn hooks per this post

And also had to downgrade scikit-learn to 0.21.

  • scikit-learn==0.22.1 doesn't work with DVHA at all
  • scikit-learn==0.22 didn't work with pyinstaller==3.6

I think the "reference" to user folder of my compiling PC is actually a hard-coded string of a warning output, not that the executable is trying to access that file path.

I also upgraded pip to latest dev and used setuptools==44.0.0. Will have to test if sklearn is the only issue. PyInstaller and setuptools==45.0.0 aren't playing well together: pypa/setuptools#1963

Next step is to see if there are ways to trim down the included libraries and get the executable file size smaller?

@bastula
Copy link

bastula commented Jan 17, 2020 via email

@cutright
Copy link
Owner Author

Yes, unfortunately. I also use it for PTV distance calculations.

@cutright
Copy link
Owner Author

I was able to trim 20MB from bokeh per my post over on bokeh's community page
https://discourse.bokeh.org/t/reducing-bokeh-footprint-in-venv-for-pyinstaller/4622/2

@cutright
Copy link
Owner Author

I still plan to try reducing executable size, but since the executables appear to be working I'm closing the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants