Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RESOLVED]Error with from astropy.convolution import Gaussian1DKernel #129

Open
jglorian opened this issue Jun 15, 2021 · 8 comments
Open

Comments

@jglorian
Copy link

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()
@bwoodsend bwoodsend transferred this issue from pyinstaller/pyinstaller Jun 15, 2021
@rokm
Copy link
Member

rokm commented Jun 15, 2021

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
Copy link
Member

rokm commented Jun 15, 2021

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).

@bwoodsend
Copy link
Member

Yes. I deliberately excluded that because it was said in numpy/numpy#17184 (comment) that is was unlikely to be useful (and tbh I can't understand why astropy would need it).

@bwoodsend
Copy link
Member

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.

@rokm
Copy link
Member

rokm commented Jun 15, 2021

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...

@bwoodsend
Copy link
Member

bwoodsend commented Jun 15, 2021

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.

@jglorian
Copy link
Author

jglorian commented Jun 16, 2021

Solved with

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

Thank you !

@jglorian jglorian changed the title Error with from astropy.convolution import Gaussian1DKernel [RESOLVED]Error with from astropy.convolution import Gaussian1DKernel Jun 16, 2021
@bwoodsend bwoodsend reopened this Jun 16, 2021
@bwoodsend
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants