Skip to content

Document considerations when deploying tests using Pyinstaller #1219

@aunsbjerg

Description

@aunsbjerg

I have a small application based on openhtf that I want to distribute to some non-technical people in my company, so to makes things easier, providing a single executable is preferable. Currently, I am looking into pyinstaller, but having some issues.

Essentially, I am able to create an executable in pyinstaller with pyinstaller --collect-data=openhtf --paths=production-tester --onedir production-tester/tester.py, but when running the executable, I get the following exception:

❯ ./dist/tester/tester --help
Traceback (most recent call last):
  File "tester.py", line 11, in <module>
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 450, in exec_module
  File "targets/chamber.py", line 68, in <module>
  File "openhtf/plugs/__init__.py", line 110, in result
    phase = phase_descriptor.PhaseDescriptor.wrap_or_copy(func)
  File "openhtf/core/phase_descriptor.py", line 259, in wrap_or_copy
    retval = cls(func)
  File "<attrs generated init openhtf.core.phase_descriptor.PhaseDescriptor>", line 6, in __init__
    self.func_location = __attr_factory_func_location(self)
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "openhtf/core/phase_descriptor.py", line 219, in _func_location
    line_number = inspect.getsourcelines(obj)[1]
                  ~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "inspect.py", line 1238, in getsourcelines
  File "inspect.py", line 1078, in findsource
OSError: could not get source code
[PYI-2911318:ERROR] Failed to execute script 'tester' due to unhandled exception!

It seems that openhtf does some runtime introspection that isn't "captured" by pyinstaller.

I realize that this might not be a openhtf issue as much as it is a pyinstaller issue, but I am asking in the hope that someone else might have had the same problem and found a solution.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions