astropy: Latest Anaconda python incompatible with astropy 5.1 & 5.2 (WCSAxes.__init__() got multiple values for argument 'wcs')

Description

I was trying to use wcs on an image following the steps in https://docs.astropy.org/en/stable/visualization/wcsaxes/index.html with astropy v5.1 and anaconda/python v 3.10 but I got an error:

WCSAxes.__init__() got multiple values for argument 'wcs'

I tried updating astropy to the latest version (5.2) with ‘conda update astropy’ but this had catastrophic effects of disappearing ipython and jupyter-notebook as well as other “jupyter-” executables from my anaconda3/bin/ directory (I dont understand how this is possible, but I confirmed it twice now). numpy also got corrupted, requiring me to completely uninstall anaconda and re-install it (which revived the astropy 5.1 version, but the wcs issue persists).

My older computer has python 3.7 and astropy 4.3 and the code works just fine (so I will not be updating on that machine for now) so the issue seems to be compatibility between the two.

Expected behavior

The code outlined in https://docs.astropy.org/en/stable/visualization/wcsaxes/index.html should work but instead the command

plt.subplot(projection=wcs)

results in these errors:

In [3]: plt.subplot(projection=wcs)
   ...: 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 plt.subplot(projection=wcs)

File ~/anaconda3/lib/python3.10/site-packages/matplotlib/pyplot.py:1311, in subplot(*args, **kwargs)
   1308             break
   1309 else:
   1310     # we have exhausted the known Axes and none match, make a new one!
-> 1311     ax = fig.add_subplot(*args, **kwargs)
   1313 fig.sca(ax)
   1315 axes_to_delete = [other for other in fig.axes
   1316                   if other != ax and ax.bbox.fully_overlaps(other.bbox)]

File ~/anaconda3/lib/python3.10/site-packages/matplotlib/figure.py:743, in FigureBase.add_subplot(self, *args, **kwargs)
    740         args = tuple(map(int, str(args[0])))
    741     projection_class, pkw = self._process_projection_requirements(
    742         *args, **kwargs)
--> 743     ax = projection_class(self, *args, **pkw)
    744     key = (projection_class, pkw)
    745 return self._add_axes_internal(ax, key)

TypeError: WCSAxes.__init__() got multiple values for argument 'wcs'

Versions

import platform; print(platform.platform()) import sys; print(“Python”, sys.version) import astropy; print(“astropy”, astropy.version) import numpy; print(“Numpy”, numpy.version) import erfa; print(“pyerfa”, erfa.version) import scipy; print(“Scipy”, scipy.version) import matplotlib; print(“Matplotlib”, matplotlib.version)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 18 (10 by maintainers)

Most upvoted comments

Hi Stuart,

Thanks for all of this – I was pulled away for something else but came back to this today. Slowly re-building things in what will hopefully be a more sensible structure. I’ll report back if I run into any more problems. Right now, i realize that installing miniforge3 does not include ipython or jupyter notebooks so i need to get those first before i can test anything.

On Fri, May 12, 2023 at 11:11 AM Stuart Mumford @.***> wrote:

There is a legitimate issue with anaconda / defaults that we need to reach out to someone at anaconda about, and that is that the lastest version of astropy available in defaults is 5.1.0 which is incompatible with matplotlib 3.7.0, so someone using defaults is completely broken.

@eilatg https://github.com/eilatg I am sorry that your early forays into Python have run into a pretty awkward bug! Let me try and explain why I recommend what I do.

First, let’s clarify some things up front:

  • conda is a package manager, and anaconda is a scientific python distribution which uses the conda package manager, but comes with a large set of packages installed to get people started.
  • Conda “environments” or Python’s “virtual environments” allow you to have many different isolated sets of packages installed alongside each other an allow you to decide which set you need for a specific task. Back in my research days, I would have an environment setup for each project I was working on, which allowed me to update or install a package for one project without risking breaking a different one.

The other thing to understand is that there are two primary sources for packages that can be installed with conda, these sources are called “channels”, there’s “defaults” which is maintained by Anaconda Inc. and there’s conda-forge which is a community project (the anaconda distribution uses “defaults”). There’s more choice and, often, more upto date packages available on conda-forge.

So all that being said, what I recommend is the following:

  • Use miniforge https://github.com/conda-forge/miniforge/ to install Python & conda.: Miniforge, is like a super minimal version of anaconda which only installs Python itself and the conda command, this gives you all the building blocks you need to install packages yourself. The alternative here is miniconda https://docs.conda.io/en/latest/miniconda.html, which is basically the same, with one key difference: miniforge uses conda-forge and not defaults.
  • Use environments for everything: When you have installed miniforge (or miniconda) the “base” environment will have basically nothing installed other than the python command and the conda command. Rather than installing anything else in the base env, I highly recommend starting a new env and then installing whatever you need in that environment. So if you have used miniforge, the following two commands:

$ conda create --name astropy $ conda install astropy

will make a new environment and install the latest version of astropy into it (5.2.2), which is newer than the one available in anaconda/defaults.

Hope that helps clarify what’s going on!

— Reply to this email directly, view it on GitHub https://github.com/astropy/astropy/issues/14817#issuecomment-1545899259, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB73GSLJHY6TRUPI4GLHUUTXFZHLVANCNFSM6AAAAAAX6VGEQM . You are receiving this because you were mentioned.Message ID: @.***>

This appears to be the same / similar to: https://github.com/sunpy/sunpy/issues/6946 which is that matplotlib 3.7.0 and astropy 5.1.0 are incompatible with one another, you need astropy 5.1.1 which has the bug fix for matplotlib 3.7.0 in it.

@eilatg What I would like to clarify is that with a completely clean anaconda installation you are getting version 5.1.0 of astropy and 3.7.0 of matplotlib and run into this error, without running any other install commands?

If that’s the case then it’s anaconda itself which is shipping an incompatible set of packages (not entirely its fault as there’s no metadata to tell them it’s broken).

Given all of that, I would think the fix which is likely to be the least disruptive and might actually work is after installing anaconda run conda install astropy==5.1.1, that should fix the bug without doing any other major version bumps which might cause the anaconda house of cards to come tumbling down.


P.S. like @pllim I also recommend that people don’t use full-blown anaconda, install conda with miniconda or miniforge and then make conda envs.