Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pyinstaller to pack into exe file and get no device. #36

Open
pineappleliubo opened this issue Aug 23, 2018 · 15 comments
Open

Use pyinstaller to pack into exe file and get no device. #36

pineappleliubo opened this issue Aug 23, 2018 · 15 comments

Comments

@pineappleliubo
Copy link

Get the transport layer factory.

tlFactory = pylon.TlFactory.GetInstance()

Get all attached devices and exit application if no device is found.

devices = tlFactory.EnumerateDevices()

if len(devices) == 0:
raise pylon.RuntimeException("No camera present.")

The above code runs normally.
But when pyinstaller is packaged into exe, the exception "RuntimeException No camera present." is thrown.

@stefanklug
Copy link
Contributor

Hi @pineappleliubo, could you try the current master? I believe this issue was fixed in c34e798

@RoccoMatano
Copy link
Contributor

Hi @pineappleliubo and @stefanklug,
i doubt that commit c34e789 fixes the reported issue. That commit fixes the problem that pypylon could not be imported at all from a pyinstaller executable. But i have to admit that i did my tests only on windows.

@pineappleliubo
Copy link
Author

Supplementary pyinstaller package process information;

A warning message is displayed in the packaging process, and the final package is successful. The EXE program cannot execute the camera device.

D:\workspace\brose\first_camera\CMQI>pyinstaller -F CMQI.py
4014 INFO: PyInstaller: 3.3.1
4016 INFO: Python: 2.7.14
4017 INFO: Platform: Windows-10-10.0.17134
4017 INFO: wrote D:\workspace\brose\first_camera\CMQI\CMQI.spec
4023 INFO: UPX is not available.
4024 INFO: Extending PYTHONPATH with paths
['D:\workspace\brose', 'D:\workspace\brose\first_camera\CMQI']
4026 INFO: checking Analysis
4128 INFO: Building because D:\workspace\brose\first_camera\CMQI\CMQI.py changed
4128 INFO: Initializing module dependency graph...
4141 INFO: Initializing module graph hooks...
4705 INFO: running Analysis out00-Analysis.toc
4730 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
required by d:\python27\python.exe
4858 INFO: Found C:\WINDOWS\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_acd0e4ffe1daef0a.manifest
4884 INFO: Found C:\WINDOWS\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9415_none_acce318be1dd48d8.manifest
4996 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.9415_none ...
4996 INFO: Found manifest C:\WINDOWS\WinSxS\Manifests\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9415_none_08e0c10ba840a28a.manifest
4999 INFO: Searching for file msvcr90.dll
5000 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9415_none_08e0c10ba840a28a\msvcr90.dll
5000 INFO: Searching for file msvcp90.dll
5000 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9415_none_08e0c10ba840a28a\msvcp90.dll
5001 INFO: Searching for file msvcm90.dll
5001 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9415_none_08e0c10ba840a28a\msvcm90.dll
5111 INFO: Found C:\WINDOWS\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_acd0e4ffe1daef0a.manifest
5111 INFO: Found C:\WINDOWS\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9415_none_acce318be1dd48d8.manifest
5112 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9415)
5292 INFO: Caching module hooks...
5302 INFO: Analyzing D:\workspace\brose\first_camera\CMQI\CMQI.py
14582 INFO: Processing pre-find module path hook distutils
17394 INFO: Processing pre-safe import module hook xmlplus
22825 INFO: Processing pre-safe import module hook six.moves
27210 INFO: Processing pre-find module path hook site
27217 INFO: site: retargeting to fake-dir 'd:\python27\lib\site-packages\PyInstaller\fake-modules'
35859 INFO: Processing pre-safe import module hook urllib3.packages.six.moves
83546 INFO: Loading module hooks...
83546 INFO: Loading module hook "hook-shelve.py"...
83547 WARNING: Hidden import "dbm.ndbm" not found!
83547 WARNING: Hidden import "dbm.dumb" not found!
83549 WARNING: Hidden import "dbm.gnu" not found!
83549 INFO: Loading module hook "hook-distutils.py"...
83562 INFO: Loading module hook "hook-sysconfig.py"...
83566 INFO: Loading module hook "hook-xml.py"...
83569 INFO: Loading module hook "hook-PIL.py"...
83572 INFO: Excluding import 'FixTk'
83575 INFO: Excluding import 'Tkinter'
83578 INFO: Excluding import 'PyQt5'
83579 INFO: Removing import of PyQt5.QtCore from module PIL.ImageQt
83580 INFO: Removing import of PyQt5.QtGui from module PIL.ImageQt
83580 INFO: Excluding import 'PySide'
83583 INFO: Removing import of PySide from module PIL.ImageQt
83583 INFO: Excluding import 'PyQt4'
83586 INFO: Removing import of PyQt4 from module PIL.ImageQt
83588 INFO: Loading module hook "hook-zmq.py"...
87257 WARNING: Hidden import "No" not found!
87260 WARNING: Hidden import "file:" not found!
87263 WARNING: Hidden import "d:\python27\lib\site-packages\zmq\backend\cffi_pycache
_cffi_ext.c(213)" not found!
87411 WARNING: Hidden import "file" not found!
87414 WARNING: Hidden import "open" not found!
87417 WARNING: Hidden import ":" not found!
87420 WARNING: Hidden import "Cannot" not found!
87424 WARNING: Hidden import "fatal" not found!
87425 WARNING: Hidden import "C1083:" not found!
87430 WARNING: Hidden import "such" not found!
87434 WARNING: Hidden import "include" not found!
87435 WARNING: Hidden import "'sys/un.h':" not found!
87438 WARNING: Hidden import "directory" not found!
87441 WARNING: Hidden import "_cffi_ext.c" not found!
87444 WARNING: Hidden import "or" not found!
87447 INFO: Excluding import 'zmq.libzmq'
87450 INFO: Removing import of zmq.libzmq from module zmq
87451 INFO: Loading module hook "hook-cryptography.py"...
88618 INFO: Loading module hook "hook-pycparser.py"...
88886 INFO: Loading module hook "hook-jinja2.py"...
88928 INFO: Loading module hook "hook-PyQt5.QtWidgets.py"...
88930 INFO: Loading module hook "hook-httplib.py"...
88930 INFO: Loading module hook "hook-pydoc.py"...
88934 INFO: Excluding import 'Tkinter'
88935 INFO: Removing import of Tkinter from module pydoc
88937 INFO: Loading module hook "hook-pygments.py"...
91727 INFO: Loading module hook "hook-PyQt5.py"...
91738 INFO: Loading module hook "hook-jsonschema.py"...
91756 INFO: Loading module hook "hook-_tkinter.py"...
92228 INFO: checking Tree
92358 INFO: checking Tree
92418 INFO: Loading module hook "hook-matplotlib.backends.py"...
93865 INFO: Matplotlib backend "GTK": ignored
Gtk* backend requires pygtk to be installed.
95240 INFO: Matplotlib backend "GTKAgg": ignored
Gtk* backend requires pygtk to be installed.
95542 INFO: Matplotlib backend "GTKCairo": ignored
No module named gtk
95997 INFO: Matplotlib backend "MacOSX": ignored
cannot import name _macosx
97284 INFO: Matplotlib backend "Qt4Agg": added
97848 INFO: Matplotlib backend "Qt5Agg": added
103365 INFO: Matplotlib backend "TkAgg": added
114460 INFO: Matplotlib backend "WX": added
114950 INFO: Matplotlib backend "WXAgg": added
115266 INFO: Matplotlib backend "GTK3Cairo": ignored
Cairo backend requires that cairocffi or pycairo is installed.
115720 INFO: Matplotlib backend "GTK3Agg": ignored
Gtk3 backend requires pygobject to be installed.
117006 INFO: Matplotlib backend "WebAgg": added
119543 INFO: Matplotlib backend "nbAgg": added
119973 INFO: Matplotlib backend "agg": added
120283 INFO: Matplotlib backend "cairo": ignored
Cairo backend requires that cairocffi or pycairo is installed.
120582 INFO: Matplotlib backend "gdk": ignored
No module named gobject
121034 INFO: Matplotlib backend "pdf": added
122243 INFO: Matplotlib backend "pgf": added
122698 INFO: Matplotlib backend "ps": added
123203 INFO: Matplotlib backend "svg": added
123621 INFO: Matplotlib backend "template": added
124306 INFO: Loading module hook "hook-PIL.Image.py"...
125096 INFO: Loading module hook "hook-matplotlib.py"...
125486 INFO: Loading module hook "hook-xml.dom.domreg.py"...
125486 INFO: Loading module hook "hook-pkg_resources.py"...
126703 INFO: Processing pre-safe import module hook win32com
127437 INFO: Loading module hook "hook-requests.py"...
127440 INFO: Loading module hook "hook-lxml.objectify.py"...
127441 INFO: Loading module hook "hook-cv2.py"...
127443 INFO: Loading module hook "hook-gevent.monkey.py"...
127471 INFO: Loading module hook "hook-IPython.py"...
127542 INFO: Excluding import 'Tkinter'
127546 INFO: Removing import of Tkinter from module IPython.lib.clipboard
127549 INFO: Excluding import 'PySide'
127555 INFO: Removing import of PySide from module IPython.external.qt_loaders
127557 INFO: Excluding import 'gtk'
127565 INFO: Excluding import 'PyQt5'
127570 INFO: Removing import of PyQt5.QtWidgets from module IPython.external.qt_loaders
127570 INFO: Removing import of PyQt5.QtSvg from module IPython.external.qt_loaders
127572 INFO: Removing import of PyQt5.QtGui from module IPython.external.qt_loaders
127573 INFO: Removing import of PyQt5 from module IPython.external.qt_loaders
127578 INFO: Removing import of PyQt5.QtCore from module IPython.external.qt_loaders
127582 INFO: Excluding import 'PyQt4'
127585 INFO: Removing import of PyQt4 from module IPython.external.qt_loaders
127589 INFO: Excluding import 'matplotlib'
127596 INFO: Removing import of matplotlib._pylab_helpers from module IPython.core.pylabtools
127598 INFO: Removing import of matplotlib.pyplot from module IPython.core.pylabtools
127598 INFO: Removing import of matplotlib from module IPython.core.pylabtools
127601 INFO: Removing import of matplotlib.figure from module IPython.core.pylabtools
127605 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
127836 INFO: Loading module hook "hook-certifi.py"...
127839 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
128500 INFO: Loading module hook "hook-pytz.py"...
128766 INFO: Loading module hook "hook-pywintypes.py"...
129631 INFO: Loading module hook "hook-setuptools.py"...
129714 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
129720 INFO: Excluding import 'FixTk'
129723 INFO: Excluding import 'Tkinter'
129726 INFO: Loading module hook "hook-PyQt5.Qt.py"...
129727 INFO: Loading module hook "hook-encodings.py"...
130986 INFO: Loading module hook "hook-pytest.py"...
132411 INFO: Loading module hook "hook-numpy.core.py"...
132490 INFO: MKL libraries found when importing numpy. Adding MKL to binaries
132494 INFO: Loading module hook "hook-sqlite3.py"...
132688 INFO: Loading module hook "hook-PyQt5.QtSvg.py"...
132690 INFO: Loading module hook "hook-win32com.py"...
133957 INFO: Loading module hook "hook-pythoncom.py"...
134833 INFO: Loading module hook "hook-PyQt5.QtPrintSupport.py"...
134950 INFO: Loading module hook "hook-lxml.etree.py"...
135023 INFO: Looking for ctypes DLLs
135240 INFO: Analyzing run-time hooks ...
135256 INFO: Including run-time hook 'pyi_rth_pkgres.py'
135273 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
135279 INFO: Including run-time hook 'pyi_rth__tkinter.py'
135282 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
135286 INFO: Including run-time hook 'pyi_rth_traitlets.py'
135287 INFO: Including run-time hook 'pyi_rth_qt5.py'
135289 INFO: Including run-time hook 'pyi_rth_mplconfig.py'
135290 INFO: Including run-time hook 'pyi_rth_mpldata.py'
135325 INFO: Looking for dynamic libraries
135728 WARNING: lib not found: msmpi.dll dependency of d:\python27\Library\bin\mkl_blacs_msmpi_ilp64.dll
137924 WARNING: lib not found: impi.dll dependency of d:\python27\Library\bin\mkl_blacs_intelmpi_ilp64.dll
142244 WARNING: lib not found: msmpi.dll dependency of d:\python27\Library\bin\mkl_blacs_msmpi_lp64.dll
144134 WARNING: lib not found: pgc14.dll dependency of d:\python27\Library\bin\mkl_pgi_thread.dll
144516 WARNING: lib not found: pgf90rtl.dll dependency of d:\python27\Library\bin\mkl_pgi_thread.dll
144897 WARNING: lib not found: pgf90.dll dependency of d:\python27\Library\bin\mkl_pgi_thread.dll
146832 WARNING: lib not found: tbb.dll dependency of d:\python27\Library\bin\mkl_tbb_thread.dll
148690 WARNING: lib not found: impi.dll dependency of d:\python27\Library\bin\mkl_blacs_intelmpi_lp64.dll
159095 WARNING: lib not found: mpich2mpi.dll dependency of d:\python27\Library\bin\mkl_blacs_mpich2_lp64.dll
159562 WARNING: lib not found: mpich2mpi.dll dependency of d:\python27\Library\bin\mkl_blacs_mpich2_ilp64.dll
161098 INFO: Found C:\WINDOWS\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.4148_none_a551ff35e6a96bed.manifest
161220 INFO: Searching for assembly amd64_Microsoft.VC90.MFC_1fc8b3b9a1e18e3b_9.0.30729.4148_none ...
161221 INFO: Found manifest C:\WINDOWS\WinSxS\Manifests\amd64_microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.4148_none_04480933ab2137b1.manifest
161230 INFO: Searching for file mfc90.dll
161231 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.4148_none_04480933ab2137b1\mfc90.dll
161233 INFO: Searching for file mfc90u.dll
161233 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.4148_none_04480933ab2137b1\mfc90u.dll
161233 INFO: Searching for file mfcm90.dll
161233 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.4148_none_04480933ab2137b1\mfcm90.dll
161233 INFO: Searching for file mfcm90u.dll
161234 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.4148_none_04480933ab2137b1\mfcm90u.dll
161342 INFO: Found C:\WINDOWS\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.4148_none_a551ff35e6a96bed.manifest
161345 INFO: Adding redirect Microsoft.VC90.MFC version (9, 0, 21022, 8) -> (9, 0, 30729, 4148)
162165 WARNING: lib not found: libzmq.pyd dependency of d:\python27\lib\site-packages\zmq\backend\cython\context.pyd
162526 WARNING: lib not found: libzmq.pyd dependency of d:\python27\lib\site-packages\zmq\backend\cython_version.pyd
162924 WARNING: lib not found: libzmq.pyd dependency of d:\python27\lib\site-packages\zmq\backend\cython\utils.pyd
163309 WARNING: lib not found: libzmq.pyd dependency of d:\python27\lib\site-packages\zmq\backend\cython_device.pyd
163707 WARNING: lib not found: libzmq.pyd dependency of d:\python27\lib\site-packages\zmq\backend\cython_poll.pyd
164059 WARNING: lib not found: libzmq.pyd dependency of d:\python27\lib\site-packages\zmq\backend\cython\error.pyd
164461 WARNING: lib not found: libzmq.pyd dependency of d:\python27\lib\site-packages\zmq\backend\cython\message.pyd
164897 WARNING: lib not found: libzmq.pyd dependency of d:\python27\lib\site-packages\zmq\backend\cython\socket.pyd
173552 INFO: Looking for eggs
173552 INFO: Using Python library d:\python27\python27.dll
173553 INFO: Found binding redirects:
[BindingRedirect(name=u'Microsoft.VC90.MFC', language=None, arch=u'amd64', oldVersion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 4148), publicKeyToken=u'1fc8b3b9a1e18e3b'), BindingRedirect(name=u'Microsoft.VC90.CRT', language=None, arch=u'amd64', oldVersion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 9415), publicKeyToken=u'1fc8b3b9a1e18e3b')]
173566 INFO: Warnings written to D:\workspace\brose\first_camera\CMQI\build\CMQI\warnCMQI.txt
173863 INFO: Graph cross-reference written to D:\workspace\brose\first_camera\CMQI\build\CMQI\xref-CMQI.html
174530 INFO: checking PYZ
174603 INFO: Building because D:\workspace\brose\first_camera\CMQI\pyplon.py changed
174605 INFO: Building PYZ (ZlibArchive) D:\workspace\brose\first_camera\CMQI\build\CMQI\out00-PYZ.pyz
178632 INFO: Building PYZ (ZlibArchive) D:\workspace\brose\first_camera\CMQI\build\CMQI\out00-PYZ.pyz completed successfully.
178974 INFO: checking PKG
179016 INFO: Building because D:\workspace\brose\first_camera\CMQI\build\CMQI\out00-PYZ.pyz changed
179016 INFO: Building PKG (CArchive) out00-PKG.pkg
188371 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9415)
301139 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
301424 INFO: Bootloader d:\python27\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
301425 INFO: checking EXE
301488 INFO: Rebuilding out00-EXE.toc because pkg is more recent
301490 INFO: Building EXE from out00-EXE.toc
301493 INFO: Appending archive to EXE D:\workspace\brose\first_camera\CMQI\dist\CMQI.exe
301705 INFO: Building EXE from out00-EXE.toc completed successfully.

D:\workspace\brose\first_camera\CMQI>

@RoccoMatano
Copy link
Contributor

Hi @pineappleliubo,
I see that you are using Python 2.7. Can you try to reproduce the issue with a more current Python version (e.g. 3.6 or 3.7)?

@pineappleliubo
Copy link
Author

@RoccoMatano
I haven't tried any other version of Python yet. I think I can try it.

@fncnt
Copy link

fncnt commented Oct 30, 2018

Apparently pyinstaller copies the pylon driver DLL files into the dist directory but misses some of them.
Depending on the camera type you're using, you can manually specify which binary files pyinstaller should include by using the generated .spec file.
You can find the specific files in the pylon Deployment Guide.
In my case pyinstaller didn't include 3 pylon files necessary for USB3 vision cameras which were listed in the deployment guide:
Just open CMQI.spec and include the missing files in the Analysis object a:

binaries=[('C:\\Program Files\\Basler\\pylon 5\\Runtime\\x64\\ProducerU3V.cti', '.'),
          ('C:\\Program Files\\Basler\\pylon 5\\Runtime\\x64\\PylonUsb_MD_VC120_V5_0_TL.dll', '.'),
          ('C:\\Program Files\\Basler\\pylon 5\\Runtime\\x64\\uxapi_v10.dll', '.')],

You probably need some other files if you're not using a USB3 vision camera.
Then you can freeze your script by running:

pyinstaller CMQI.spec

@RoccoMatano
Copy link
Contributor

I think @fncnt pointed in the right direction. But i would solve it this way:

# Pyinstallers dependency analysis will not detect that pylons TL DLLs are
# required (since they are searched and loaded from machine code at runtime).
# Consequently it would not include them in the archive. This is amended by
# simply adding all DLLs from the pypylon directory to the list of binaries.

import pypylon
import pathlib
pypylon_dir = pathlib.Path(pypylon.__file__).parent
pylon_dlls = [(str(dll), '.') for dll in pypylon_dir.glob('*.dll')]

a = Analysis(
    ...
    binaries=pylon_dlls,        # make sure pylons TL DLLs are added
    ...
    )

@ByteArts
Copy link

ByteArts commented Feb 19, 2019

I am having this same problem. I've tried the solutions suggested by @fncnt and @RoccoMatano , but when running the executable generated by pyinstaller, no camera is ever found. The same code works fine when run with Python and finds my camera.

Details:
Using Python 2.7.15 (64 bits), Windows 8.1. Camera is a daA1600-60um. I have the most recent version of pypylon (V1.3.1) installed.

I've modified the .spec file to include ALL the files in the Runtime/x64 folder. The program file I'm using is this (filename is enum_cameras.py):

from pypylon import pylon

tlFactory = pylon.TlFactory.GetInstance()

# Get all attached devices and exit application if no device is found.
devices = tlFactory.EnumerateDevices()

if len(devices) == 0:
    raise pylon.RuntimeException("No camera present.")
else:
    print '%d camera(s) found' % len(devices)

When I run the executable, I get this output:
Traceback (most recent call last):
File "enum_cameras.py", line 9, in
_genicam.RuntimeException: No camera present.
[4084] Failed to execute script enum_cameras

Is there a way to get more detailed debugging information?

UPDATE: Problem was me... the solution given by @RoccoMatano does indeed work -- I had a typo in my .spec file. Fixed it, and now it's all hunky-dory!

@yaochuang001
Copy link

I have encountered the same problem, what should I do according to your method?@RoccoMatano

@ByteArts
Copy link

ByteArts commented May 13, 2019

Here's the .spec file I used - maybe this will help. You have pass the .spec file to pyinstaller instead of the .py file, so in this case I use "pyinstaller example.spec"

# -*- mode: python -*-

block_cipher = None

# Pyinstallers dependency analysis will not detect that pylons TL DLLs are
# required (since they are searched and loaded from machine code at runtime).
# Consequently it would not include them in the archive. This is amended by
# simply adding all DLLs from the pypylon directory to the list of binaries.

import pypylon
import pathlib
pypylon_dir = pathlib.Path(pypylon.__file__).parent
pylon_dlls = [(str(dll), '.') for dll in pypylon_dir.glob('*.dll')]


a = Analysis(['example.py'], 
    pathex=['E:\\Projects\\example'],
    binaries=pylon_dlls,
    datas=[],
    hiddenimports=[],
    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,
     [],
     exclude_binaries=True,
     name='example',
     debug=False,
     bootloader_ignore_signals=False,
     strip=False,
     upx=True,
     console=True )
coll = COLLECT(exe,
       a.binaries,
       a.zipfiles,
       a.datas,
       strip=False,
       upx=True,
       name='example')

@yaochuang001
Copy link

Here's the .spec file I used - maybe this will help. You have pass the .spec file to pyinstent

Here's the .spec file I used - maybe this will help. You have pass the .spec file to pyinstaller instead of the .py file, so in this case I use "pyinstaller example.spec"

# -*- mode: python -*-

block_cipher = None

# Pyinstallers dependency analysis will not detect that pylons TL DLLs are
# required (since they are searched and loaded from machine code at runtime).
# Consequently it would not include them in the archive. This is amended by
# simply adding all DLLs from the pypylon directory to the list of binaries.

import pypylon
import pathlib
pypylon_dir = pathlib.Path(pypylon.__file__).parent
pylon_dlls = [(str(dll), '.') for dll in pypylon_dir.glob('*.dll')]


a = Analysis(['example.py'], 
    pathex=['E:\\Projects\\example'],
    binaries=pylon_dlls,
    datas=[],
    hiddenimports=[],
    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,
     [],
     exclude_binaries=True,
     name='example',
     debug=False,
     bootloader_ignore_signals=False,
     strip=False,
     upx=True,
     console=True )
coll = COLLECT(exe,
       a.binaries,
       a.zipfiles,
       a.datas,
       strip=False,
       upx=True,
       name='example')

I am not familiar enough with pyinstaller, and I am too careless. Now it works.thank you very much

@lee2430
Copy link

lee2430 commented Jun 27, 2019

@RoccoMatano Thank you very much. I encountered the same problem, and directly solve it with your method. You saved me much time. Thanks again!

@crunchyluke
Copy link

Just wanted to add that if you are "compiling" a python script on Linux, @RoccoMatano's answer above works with one small modification:

pylon_dlls = [(str(dll), '.') for dll in pypylon_dir.glob('*.dll')]

must be changed to:

pylon_dlls = [(str(dll), '.') for dll in pypylon_dir.glob('*.so')]

as Linux uses .so files instead of .dll files for shared libraries.

@pwuertz
Copy link

pwuertz commented Aug 20, 2020

Just hit this problem as well. I tried fixing the problem by creating hook-pypylon.py and using the PyInstaller utility methods to do the work. collect_dynamic_libs indeed finds all the dll/so files and places them in the pypylon subfolder, just like the original layout. Unfortunately, for some reason the installed process requires all the pypylon libs to be installed into the deploy root folder (i.e. not in ./pypylon). This hook script does the trick for me:

# hook-pypylon.py
from PyInstaller.utils.hooks import collect_dynamic_libs

binaries = [
    (lib, ".") for lib, path in
    collect_dynamic_libs("pypylon")
]

@pwuertz
Copy link

pwuertz commented Feb 1, 2021

I'm not sure if this is due to a specific change in pypylon or PyInstaller, but I had to modify the hook-pypylon.py to get a working bundle with current versions:

# hook-pypylon.py (requires python 3.8)
import importlib.metadata

pypylon_dist = importlib.metadata.distribution("pypylon")
base_path = pypylon_dist.locate_file(".")
dynamic_libs = [
    (base_path / f) for f in pypylon_dist.files
    if f.suffix.lower() in (".so", ".dll", ".dylib")
]

binaries = [(lib, ".") for lib in dynamic_libs]

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

No branches or pull requests

9 participants