ImportError while importing APLpy

1.1k Views Asked by At

I keep getting this import error whenever I try to import APLpy in iPython after astropy.io.fits. I've tried uninstalling and reinstalling all my Python packages and libraries. This error is causing kernel panic and I keep getting the login warning "You restarted your computer because of a problem".

ImportError                               Traceback (most recent call last)
<ipython-input-2-ab2ae99f459c> in <cell line: 1>()
----> 1 import aplpy

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aplpy/__init__.py in <module>
     12 if not _ASTROPY_SETUP_:  # noqa
     13 
---> 14     from .core import FITSFigure  # noqa
     15     from .rgb import make_rgb_image, make_rgb_cube  # noqa
     16 

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aplpy/core.py in <module>
     18 from astropy.wcs.utils import proj_plane_pixel_scales
     19 from astropy.io import fits
---> 20 from astropy.nddata.utils import block_reduce
     21 from astropy.visualization import AsymmetricPercentileInterval
     22 from astropy.visualization.wcsaxes import WCSAxes, WCSAxesSubplot

ImportError: cannot import name 'block_reduce' from 'astropy.nddata.utils' (/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/astropy/nddata/utils.py)
4

There are 4 best solutions below

0
On

This was fixed just a few days ago as of writing, and released as part of v2.1.0: https://github.com/aplpy/aplpy/commit/e8c72f04c0a897fd2dc43bad0fb6eeab0c413768

It was just a slight incompatibility with Astropy 5.0.

0
On

Just a heads-up: At the time of writing (August 2023), v. 2.0.3 is still the highest version of Aplpy included in Conda, so one will have to uninstall the Conda version and install the pip version to make it work until the Conda folks bump the Aplpy version to something that is not broken.

0
On

First upgrade astropy with:

pip install astropy --upgrade

Now uninstall aplpy:

pip uninstall aplpy

Then install it again:

pip install aplpy

It should work now.

0
On

Just uninstall aplpy and then install again. It works for me as I am using astropy version astropy==5.1

pip uninstall aplpy

and Install again--

pip install aplpy