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