diagnose.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/usr/bin/env python3
  2. import os
  3. import sys
  4. import tempfile
  5. def run_command(cmd):
  6. print('Running %r:' % (cmd))
  7. os.system(cmd)
  8. print('------')
  9. def run():
  10. _path = os.getcwd()
  11. os.chdir(tempfile.gettempdir())
  12. print('------')
  13. print('os.name=%r' % (os.name))
  14. print('------')
  15. print('sys.platform=%r' % (sys.platform))
  16. print('------')
  17. print('sys.version:')
  18. print(sys.version)
  19. print('------')
  20. print('sys.prefix:')
  21. print(sys.prefix)
  22. print('------')
  23. print('sys.path=%r' % (':'.join(sys.path)))
  24. print('------')
  25. try:
  26. import numpy
  27. has_newnumpy = 1
  28. except ImportError as e:
  29. print('Failed to import new numpy:', e)
  30. has_newnumpy = 0
  31. try:
  32. from numpy.f2py import f2py2e
  33. has_f2py2e = 1
  34. except ImportError as e:
  35. print('Failed to import f2py2e:', e)
  36. has_f2py2e = 0
  37. try:
  38. import numpy.distutils
  39. has_numpy_distutils = 2
  40. except ImportError:
  41. try:
  42. import numpy_distutils
  43. has_numpy_distutils = 1
  44. except ImportError as e:
  45. print('Failed to import numpy_distutils:', e)
  46. has_numpy_distutils = 0
  47. if has_newnumpy:
  48. try:
  49. print('Found new numpy version %r in %s' %
  50. (numpy.__version__, numpy.__file__))
  51. except Exception as msg:
  52. print('error:', msg)
  53. print('------')
  54. if has_f2py2e:
  55. try:
  56. print('Found f2py2e version %r in %s' %
  57. (f2py2e.__version__.version, f2py2e.__file__))
  58. except Exception as msg:
  59. print('error:', msg)
  60. print('------')
  61. if has_numpy_distutils:
  62. try:
  63. if has_numpy_distutils == 2:
  64. print('Found numpy.distutils version %r in %r' % (
  65. numpy.distutils.__version__,
  66. numpy.distutils.__file__))
  67. else:
  68. print('Found numpy_distutils version %r in %r' % (
  69. numpy_distutils.numpy_distutils_version.numpy_distutils_version,
  70. numpy_distutils.__file__))
  71. print('------')
  72. except Exception as msg:
  73. print('error:', msg)
  74. print('------')
  75. try:
  76. if has_numpy_distutils == 1:
  77. print(
  78. 'Importing numpy_distutils.command.build_flib ...', end=' ')
  79. import numpy_distutils.command.build_flib as build_flib
  80. print('ok')
  81. print('------')
  82. try:
  83. print(
  84. 'Checking availability of supported Fortran compilers:')
  85. for compiler_class in build_flib.all_compilers:
  86. compiler_class(verbose=1).is_available()
  87. print('------')
  88. except Exception as msg:
  89. print('error:', msg)
  90. print('------')
  91. except Exception as msg:
  92. print(
  93. 'error:', msg, '(ignore it, build_flib is obsolute for numpy.distutils 0.2.2 and up)')
  94. print('------')
  95. try:
  96. if has_numpy_distutils == 2:
  97. print('Importing numpy.distutils.fcompiler ...', end=' ')
  98. import numpy.distutils.fcompiler as fcompiler
  99. else:
  100. print('Importing numpy_distutils.fcompiler ...', end=' ')
  101. import numpy_distutils.fcompiler as fcompiler
  102. print('ok')
  103. print('------')
  104. try:
  105. print('Checking availability of supported Fortran compilers:')
  106. fcompiler.show_fcompilers()
  107. print('------')
  108. except Exception as msg:
  109. print('error:', msg)
  110. print('------')
  111. except Exception as msg:
  112. print('error:', msg)
  113. print('------')
  114. try:
  115. if has_numpy_distutils == 2:
  116. print('Importing numpy.distutils.cpuinfo ...', end=' ')
  117. from numpy.distutils.cpuinfo import cpuinfo
  118. print('ok')
  119. print('------')
  120. else:
  121. try:
  122. print(
  123. 'Importing numpy_distutils.command.cpuinfo ...', end=' ')
  124. from numpy_distutils.command.cpuinfo import cpuinfo
  125. print('ok')
  126. print('------')
  127. except Exception as msg:
  128. print('error:', msg, '(ignore it)')
  129. print('Importing numpy_distutils.cpuinfo ...', end=' ')
  130. from numpy_distutils.cpuinfo import cpuinfo
  131. print('ok')
  132. print('------')
  133. cpu = cpuinfo()
  134. print('CPU information:', end=' ')
  135. for name in dir(cpuinfo):
  136. if name[0] == '_' and name[1] != '_' and getattr(cpu, name[1:])():
  137. print(name[1:], end=' ')
  138. print('------')
  139. except Exception as msg:
  140. print('error:', msg)
  141. print('------')
  142. os.chdir(_path)
  143. if __name__ == "__main__":
  144. run()