pyinstaller-hooks-contrib icon indicating copy to clipboard operation
pyinstaller-hooks-contrib copied to clipboard

[RESOLVED]Error with from astropy.convolution import Gaussian1DKernel

Open jglorian opened this issue 4 years ago • 8 comments

When I try to run the program packaged with pyinstaller with the code below, I have

Traceback (most recent call last): File "astropy/convolution/convolve.py", line 24, in File "numpy/ctypeslib.py", line 127, in load_library ModuleNotFoundError: No module named 'numpy.distutils'

During handling of the above exception, another exception occurred:

Traceback (most recent ## Description of the issuecall last): File "main.py", line 6, in from astropy.convolution import Gaussian1DKernel File "PyInstaller/loader/pyimod03_importers.py", line 540, in exec_module File "astropy/convolution/init.py", line 8, in File "PyInstaller/loader/pyimod03_importers.py", line 540, in exec_module File "astropy/convolution/convolve.py", line 26, in ImportError: Convolution C extension is missing. Try re-building astropy. [11847] Failed to execute script main

I have done this with python3.7, under Ubuntu and with the last version of all the libraries. I also try with different versions of python and libraries but I have still the same problem Can you help me ?

import matplotlib.pyplot as plt
from astropy.convolution import Gaussian1DKernel

if __name__ == '__main__':
    gauss_1D_kernel = Gaussian1DKernel(10)
    plt.plot(gauss_1D_kernel, drawstyle='steps')
    plt.xlabel('x [pixels]')
    plt.ylabel('value')
    plt.show()

jglorian avatar Jun 15 '21 09:06 jglorian

You'll need to add numpy.distutils (and several submodules from it) to hiddenimports. On PyInstaller 4.3, the easiest way to do so is adding --collect-submodules numpy.distutils to your pyinstaller command line.

rokm avatar Jun 15 '21 09:06 rokm

Hmm, this actually looks like a bug in our numpy hook - it explicitly excludes numpy.distutils (which is why as an above work-around, its collection needs to be forced manually).

rokm avatar Jun 15 '21 20:06 rokm

Yes. I deliberately excluded that because it was said in https://github.com/numpy/numpy/issues/17184#issuecomment-683303397 that is was unlikely to be useful (and tbh I can't understand why astropy would need it).

bwoodsend avatar Jun 15 '21 20:06 bwoodsend

I'd rather that the odd library which does somehow depend on numpy.distutils should --hiddenimport it in rather that change to numpy hook to include it by default.

bwoodsend avatar Jun 15 '21 20:06 bwoodsend

It's not astropy's fault, though - at least not directly. It's numpy.ctypeslib.load_library (that astropy uses to load its private extensions) that imports numpy.distutils. But I suppose using numpy's convenience function instead of using ctypes directly might fall under the same argument...

rokm avatar Jun 15 '21 20:06 rokm

Grrr. I really like NumPy but I seriously wish it would separate its public API from its guts from its test suite from its build system...

I guess that we'll have to remove that exclusion then.

bwoodsend avatar Jun 15 '21 21:06 bwoodsend

Solved with

pyinstaller --onefile --collect-submodules numpy.distutils main.py

Thank you !

jglorian avatar Jun 16 '21 07:06 jglorian

I'm going to keep this open as it needs to be addressed in the numpy hook.

bwoodsend avatar Jun 16 '21 11:06 bwoodsend