kikuchipy and hyperspy with pyinstaller #581
-
Hi! Previous problems: import hyperspy
import hyperspy._components.eels_arctan
import hyperspy._components.bleasdale
import hyperspy._components.doniach
import hyperspy._components.eels_double_power_law
import hyperspy._components.eels_arctan
import hyperspy._components.eels_cl_edge
import hyperspy._components.error_function
import hyperspy._components.exponential
import hyperspy._components.expression
import hyperspy._components.gaussian
import hyperspy._components.gaussianhf
import hyperspy._components.heaviside
import hyperspy._components.logistic
import hyperspy._components.lorentzian
import hyperspy._components.offset
import hyperspy._components.pes_core_line_shape
import hyperspy._components.pes_voigt
import hyperspy._components.polynomial_deprecated
import hyperspy._components.polynomial
import hyperspy._components.power_law
import hyperspy._components.rc
import hyperspy._components.pes_see
import hyperspy._components.scalable_fixed_pattern
import hyperspy._components.skew_normal
import hyperspy._components.split_voigt
import hyperspy._components.eels_vignetting
import hyperspy._components.pes_voigt
import hyperspy._components.volume_plasmon_drude
import hyperspy._components.expression
import hyperspy._components.gaussian2d
import kikuchipy
import kikuchipy.generators.virtual_bse_generator
import kikuchipy.generators._transfer_axes
import kikuchipy.io._io
import kikuchipy._util
import kikuchipy.io._util
import kikuchipy.data._data
import kikuchipy.indexing._dictionary_indexing
import kikuchipy.indexing._merge_crystal_maps
import kikuchipy.indexing._orientation_similarity_map
import kikuchipy.indexing._refinement
import kikuchipy.pattern._pattern
import kikuchipy.simulations._kikuchi_pattern_features
import kikuchipy.simulations._kikuchi_pattern_simulation
import kikuchipy.detectors.ebsd_detector
import kikuchipy.signals._kikuchipy_signal
from kikuchipy.signals._kikuchipy_signal import KikuchipySignal2D, LazyKikuchipySignal2D
import kikuchipy.signals._kikuchi_master_pattern
import kikuchipy.signals.ebsd
import kikuchipy.signals.ebsd_master_pattern
import kikuchipy.signals.ecp_master_pattern
import kikuchipy.signals.virtual_bse_image After this the final bundle is still missing hyperspy/hyperspy_extension.yaml and kikuchipy/hyperspy_extension.yaml. We can however add these to the installer and place them correctly. We use auto-py-to-exe which is just a graphical user interface for pyinstaller, making this process easier. NOW our application runs! Current problem: > hyperspy.utils.print_known_signal_types()
+--------------------+---------------------+--------------------+----------+
| signal_type | aliases | class name | package |
+--------------------+---------------------+--------------------+----------+
| DielectricFunction | dielectric function | DielectricFunction | hyperspy |
| EDS_SEM | | EDSSEMSpectrum | hyperspy |
| EDS_TEM | | EDSTEMSpectrum | hyperspy |
| EELS | TEM EELS | EELSSpectrum | hyperspy |
| hologram | | HologramImage | hyperspy |
+--------------------+---------------------+--------------------+----------+ So it appears that in our executable, hyperspy does not recognize signals from kikutchipy, however it does when running it in our virtual python environment used when developing. This creates errors in our executable, when trying to run some kikutchipy functions that rely on hyperspy, mainly when we try to run s.remove_static_background() we get the following callstack with an error. Call stack:
File "main.py", line 384, in <module>
File "main.py", line 140, in <lambda>
File "main.py", line 230, in selectProcessing
File "scripts\pattern_processing.py", line 62, in <lambda>
File "scripts\pattern_processing.py", line 113, in preview_processing
File "scripts\pattern_processing.py", line 94, in remove_static
File "kikuchipy\signals\ebsd.py", line 383, in remove_static_background
File "hyperspy\signal.py", line 4904, in map
File "hyperspy\signal.py", line 5081, in _map_iterate
File "kikuchipy\signals\_kikuchipy_signal.py", line 399, in _assign_subclass
File "hyperspy\signal.py", line 5700, in _assign_subclass
File "hyperspy\io.py", line 651, in assign_signal_subclass
File "logging\__init__.py", line 1489, in warning
File "logging\__init__.py", line 1624, in _log
File "logging\__init__.py", line 1634, in handle
File "logging\__init__.py", line 1696, in callHandlers
File "logging\__init__.py", line 968, in handle
File "logging\__init__.py", line 1108, in emit
Message: "`signal_type='EBSD'` not understood. See `hs.print_known_signal_types()` for a list of installed signal types or https://github.com/hyperspy/hyperspy-extensions-list for the list of all hyperspy extensions providing signals."
Arguments: ()
Traceback (most recent call last):
File "scripts\pattern_processing.py", line 62, in <lambda>
File "scripts\pattern_processing.py", line 113, in preview_processing
File "scripts\pattern_processing.py", line 94, in remove_static
File "kikuchipy\signals\ebsd.py", line 394, in remove_static_background
AttributeError
:
'LazySignal2D' object has no attribute '_set_custom_properties' So it seems that after running map, hyperspy is not able to return the kikutchipy signal type, which first produces a warning. Therefor it is not able to call _set_custom_properties() on the returned signal, because it is a hyperspy signal instead of kikutchipy signal. Is there a workaround for this, or a different way of packaging hyperspy and kikutchipy with pyinstaller, at least so that kikutchipy signals are available in hyperspy? Our repo is avialable at: https://github.com/htrellin/EBSD-GUI/tree/dev |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi @Erlendos12, thank you for starting this discussion here. I'm not familiar with PyInstaller, so I'm afraid you have to debug this yourself. But, I can try to diagnose the problem, at least. And perhaps identify some possible solutions. The The For completeness, I should mention that HyperSpy and kikuchipy uses "lazy imports", which might be why PyInstaller's "Analysis" fails to find some imports. This is a feature of later Python versions, documented in PEP 562 (Python Enhancement Proposal number 562). The import list in the |
Beta Was this translation helpful? Give feedback.
Hi @Erlendos12,
thank you for starting this discussion here. I'm not familiar with PyInstaller, so I'm afraid you have to debug this yourself. But, I can try to diagnose the problem, at least. And perhaps identify some possible solutions.
The
AttributeError
in the error message most likely results from theEBSD.remove_static_background()
method calling theLazySignal2D.map()
method, which does not return aLazyEBSD
instance but aLazySignal2D
instance. This is because HyperSpy doesn't recognize the kikuchipy signals as subclasses of its classes.The
kikuchipy/hyperspy_extension.yaml
file must be present when installing kikuchipy, otherwise HyperSpy will not know of kikuchipy's subclasses.…