__init__.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. """
  2. SciPy: A scientific computing package for Python
  3. ================================================
  4. Documentation is available in the docstrings and
  5. online at https://docs.scipy.org/doc/scipy/
  6. Subpackages
  7. -----------
  8. ::
  9. cluster --- Vector Quantization / Kmeans
  10. constants --- Physical and mathematical constants and units
  11. datasets --- Dataset methods
  12. differentiate --- Finite difference differentiation tools
  13. fft --- Discrete Fourier transforms
  14. fftpack --- Legacy discrete Fourier transforms
  15. integrate --- Integration routines
  16. interpolate --- Interpolation Tools
  17. io --- Data input and output
  18. linalg --- Linear algebra routines
  19. ndimage --- N-D image package
  20. odr --- Orthogonal Distance Regression
  21. optimize --- Optimization Tools
  22. signal --- Signal Processing Tools
  23. sparse --- Sparse Matrices
  24. spatial --- Spatial data structures and algorithms
  25. special --- Special functions
  26. stats --- Statistical Functions
  27. Public API in the main SciPy namespace
  28. --------------------------------------
  29. ::
  30. __version__ --- SciPy version string
  31. LowLevelCallable --- Low-level callback function
  32. show_config --- Show scipy build configuration
  33. test --- Run scipy unittests
  34. """
  35. # start delvewheel patch
  36. def _delvewheel_patch_1_12_0():
  37. import os
  38. if os.path.isdir(libs_dir := os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'scipy.libs'))):
  39. os.add_dll_directory(libs_dir)
  40. _delvewheel_patch_1_12_0()
  41. del _delvewheel_patch_1_12_0
  42. # end delvewheel patch
  43. import importlib as _importlib
  44. from numpy import __version__ as __numpy_version__
  45. try:
  46. from scipy.__config__ import show as show_config
  47. except ImportError as e:
  48. msg = """Error importing SciPy: you cannot import SciPy while
  49. being in scipy source directory; please exit the SciPy source
  50. tree first and relaunch your Python interpreter."""
  51. raise ImportError(msg) from e
  52. from scipy.version import version as __version__
  53. # Allow distributors to run custom init code
  54. from . import _distributor_init
  55. del _distributor_init
  56. from scipy._lib import _pep440
  57. # In maintenance branch, change to np_maxversion N+3 if numpy is at N
  58. np_minversion = '1.26.4'
  59. np_maxversion = '2.7.0'
  60. if (_pep440.parse(__numpy_version__) < _pep440.Version(np_minversion) or
  61. _pep440.parse(__numpy_version__) >= _pep440.Version(np_maxversion)):
  62. import warnings
  63. warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
  64. f" is required for this version of SciPy (detected "
  65. f"version {__numpy_version__})",
  66. UserWarning, stacklevel=2)
  67. del _pep440
  68. # This is the first import of an extension module within SciPy. If there's
  69. # a general issue with the install, such that extension modules are missing
  70. # or cannot be imported, this is where we'll get a failure - so give an
  71. # informative error message.
  72. try:
  73. from scipy._lib._ccallback import LowLevelCallable
  74. except ImportError as e:
  75. msg = "The `scipy` install you are using seems to be broken, " + \
  76. "(extension modules cannot be imported), " + \
  77. "please try reinstalling."
  78. raise ImportError(msg) from e
  79. from scipy._lib._testutils import PytestTester
  80. test = PytestTester(__name__)
  81. del PytestTester
  82. submodules = [
  83. 'cluster',
  84. 'constants',
  85. 'datasets',
  86. 'differentiate',
  87. 'fft',
  88. 'fftpack',
  89. 'integrate',
  90. 'interpolate',
  91. 'io',
  92. 'linalg',
  93. 'ndimage',
  94. 'odr',
  95. 'optimize',
  96. 'signal',
  97. 'sparse',
  98. 'spatial',
  99. 'special',
  100. 'stats'
  101. ]
  102. __all__ = submodules + [
  103. 'LowLevelCallable',
  104. 'test',
  105. 'show_config',
  106. '__version__',
  107. ]
  108. def __dir__():
  109. return __all__
  110. def __getattr__(name):
  111. if name in submodules:
  112. return _importlib.import_module(f'scipy.{name}')
  113. else:
  114. try:
  115. return globals()[name]
  116. except KeyError:
  117. raise AttributeError(
  118. f"Module 'scipy' has no attribute '{name}'"
  119. )