4
import numpy

When I packaged above one line script as a single executable window application using py2exe, I get following warnings upon launch.

OMP: Warning #178: Function GetModuleHandleEx failed:
OMP: System error #126: The specified module could not be found.

This warning happen only when I build as single executable (i.e., only when bundle_files=1). Here's my setup.py for this.

from distutils.core import setup
import py2exe

setup(
    options = {'py2exe': {'bundle_files': 1}},
    windows=['testnumpy.py'],
    zipfile = None,
)

This problem started with numpy 1.8.0. When I revert back to 1.6.2, the warnings don't show up.

Usually a single executable packaged by py2exe will catch warnings and traceback and save them into a log file. But somehow these warnings are not captured and the app creates a console window to show warning. I want to suppress this additional console window to show up.

How can I fix this warning problem?

What I tried (nothing worked):

  1. I tried this redirecting sys.stderr.
  2. I searched github numpy source for openMP assuming the OMP stands for it as mentioned here. But, nothing useful came out.
  3. I have copied libiomp5md.dll to the same folder as setup.py.
  4. I tried filterwarnings:
  5. I tried sys.excepthook.
Community
  • 1
  • 1
otterb
  • 2,660
  • 2
  • 29
  • 48
  • 2
    Actually, I got some hint about the source of problem. The numpy installer that I used came from Python(x,y) project and it has __config__.py file in the numpy directory in site-packages. I can see libiomp5md in this file but the original numpy source don't have libiomp5md anywhere in the source. Then, I used the installer from sourceforge at http://sourceforge.net/projects/numpy/files/NumPy/1.8.1rc1/. And, the problem is gone. – otterb Mar 17 '14 at 17:10
  • Though it targets a slightly different warning, [a discussion on the Intel MKL site](https://software.intel.com/en-us/forums/topic/360825) would suggest the problem is related to an OpenMP runtime issue and not Numpy itself. As further evidence, I experience the identical Warning #178 with py2exe under Numpy 1.8.1 (no MKL optimizations) from [Anaconda](https://store.continuum.io/cshop/anaconda/). I tried setting `KMP_WARNINGS=0` in the environment, and sure enough it has no effect. The Numpy 1.8.1 build from SourceForge must be using an OpenMP version that has been fixed. – Jed Apr 30 '14 at 20:50
  • 1
    Good to know that Anaconda too has the issue. Do you mean you set KMP_WARNINGS as environment variable in windows? numpy is suppose to check this variable? Or, you tried to build numpy with such option?? – otterb May 07 '14 at 21:44
  • I can't seem to find 1.8.1rc1, the sourceforge link goes to the latest 1.9.2, and I can browse to 1.8.1, But cannot find 1.8.1rc1? any suggestions – user595985 Jul 06 '15 at 21:29

2 Answers2

3

As I wrote in the comment, installing numpy 1.8.1rc1 from sourceforge did fix the issue, although I don't really know the differences...

otterb
  • 2,660
  • 2
  • 29
  • 48
1

I had this issue with numpy 1.13.1+mkl and scipy 1.19.1. Reverting to numpy 1.8.1rc1 is not an acceptable solution.

I tracked this issue to the scipy.integrate subpackage. The warning message pops up when this package is imported. It seems that perhaps libraries that use MKL don't like being invoked from library.zip, which is where py2exe places packages when using bundle option 2.

The solution is to exclude scipy and numpy in the py2exe setup script and copy their entire package folders into the distribution directory and add that directory to the system path at the top of the main python script.

master_gibber
  • 223
  • 1
  • 8