hook-matplotlib.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2013-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 isolated
  12. from PyInstaller import compat
  13. from PyInstaller.utils import hooks as hookutils
  14. @isolated.decorate
  15. def mpl_data_dir():
  16. import matplotlib
  17. return matplotlib.get_data_path()
  18. datas = [
  19. (mpl_data_dir(), "matplotlib/mpl-data"),
  20. ]
  21. binaries = []
  22. # Windows PyPI wheels for `matplotlib` >= 3.7.0 use `delvewheel`.
  23. # In addition to DLLs from `matplotlib.libs` directory, which should be picked up automatically by dependency analysis
  24. # in contemporary PyInstaller versions, we also need to collect the load-order file. This used to be required for
  25. # python <= 3.7 (that lacked `os.add_dll_directory`), but is also needed for Anaconda python 3.8 and 3.9, where
  26. # `delvewheel` falls back to load-order file codepath due to Anaconda breaking `os.add_dll_directory` implementation.
  27. if compat.is_win and hookutils.check_requirement('matplotlib >= 3.7.0'):
  28. delvewheel_datas, delvewheel_binaries = hookutils.collect_delvewheel_libs_directory('matplotlib')
  29. datas += delvewheel_datas
  30. binaries += delvewheel_binaries