hook-numpy.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python3
  2. # --- Copyright Disclaimer ---
  3. #
  4. # In order to support PyInstaller with numpy<1.20.0 this file will be duplicated for a short period inside
  5. # PyInstaller's repository [1]. However this file is the intellectual property of the NumPy team and is
  6. # under the terms and conditions outlined their repository [2].
  7. #
  8. # .. refs:
  9. #
  10. # [1] PyInstaller: https://github.com/pyinstaller/pyinstaller/
  11. # [2] NumPy's license: https://github.com/numpy/numpy/blob/master/LICENSE.txt
  12. #
  13. """
  14. This hook should collect all binary files and any hidden modules that numpy needs.
  15. Our (some-what inadequate) docs for writing PyInstaller hooks are kept here:
  16. https://pyinstaller.readthedocs.io/en/stable/hooks.html
  17. PyInstaller has a lot of NumPy users so we consider maintaining this hook a high priority.
  18. Feel free to @mention either bwoodsend or Legorooj on Github for help keeping it working.
  19. """
  20. from PyInstaller.compat import is_conda, is_pure_conda
  21. from PyInstaller.utils.hooks import collect_dynamic_libs, is_module_satisfies
  22. # Collect all DLLs inside numpy's installation folder, dump them into built app's root.
  23. binaries = collect_dynamic_libs("numpy", ".")
  24. # If using Conda without any non-conda virtual environment manager:
  25. if is_pure_conda:
  26. # Assume running the NumPy from Conda-forge and collect it's DLLs from the communal Conda bin directory. DLLs from
  27. # NumPy's dependencies must also be collected to capture MKL, OpenBlas, OpenMP, etc.
  28. from PyInstaller.utils.hooks import conda_support
  29. datas = conda_support.collect_dynamic_libs("numpy", dependencies=True)
  30. # Submodules PyInstaller cannot detect (probably because they are only imported by extension modules, which PyInstaller
  31. # cannot read).
  32. hiddenimports = ['numpy.core._dtype_ctypes']
  33. if is_conda:
  34. hiddenimports.append("six")
  35. # Remove testing and building code and packages that are referenced throughout NumPy but are not really dependencies.
  36. excludedimports = [
  37. "scipy",
  38. "pytest",
  39. "nose",
  40. "f2py",
  41. "setuptools",
  42. "numpy.f2py",
  43. ]
  44. # As of version 1.22, numpy.testing (imported for example by some scipy modules) requires numpy.distutils and distutils.
  45. # So exclude them only for earlier versions.
  46. if is_module_satisfies("numpy < 1.22"):
  47. excludedimports += [
  48. "distutils",
  49. "numpy.distutils",
  50. ]