hook-pandas.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2017-2023, PyInstaller Development Team.
  3. #
  4. # Distributed under the terms of the GNU General Public License (version 2
  5. # or later) with exception for distributing the bootloader.
  6. #
  7. # The full license is in the file COPYING.txt, distributed with this software.
  8. #
  9. # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
  10. #-----------------------------------------------------------------------------
  11. from PyInstaller import compat
  12. from PyInstaller.utils.hooks import collect_submodules, get_installer
  13. from packaging.version import Version
  14. pandas_version = Version(compat.importlib_metadata.version("pandas")).release
  15. pandas_installer = get_installer('pandas')
  16. datas = []
  17. binaries = []
  18. # Pandas keeps Python extensions loaded with dynamic imports here.
  19. hiddenimports = collect_submodules('pandas._libs')
  20. # Pandas 1.2.0 and later require cmath hidden import on linux and macOS. On Windows, this is not strictly required, but
  21. # we add it anyway to keep things simple (and future-proof).
  22. if pandas_version >= (1, 2, 0):
  23. hiddenimports += ['cmath']
  24. # Pandas 2.1.0 started using `delvewheel` for its Windows PyPI wheels. Ensure that DLLs from `pandas.libs` directory are
  25. # collected regardless of whether binary dependency analysis manages to pick them up or not. See a similar block in the
  26. # `numpy` hook for additional explanation.
  27. if compat.is_win and pandas_version >= (2, 1, 0) and pandas_installer != 'conda':
  28. from PyInstaller.utils.hooks import collect_delvewheel_libs_directory
  29. datas, binaries = collect_delvewheel_libs_directory("pandas", datas=datas, binaries=binaries)