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

ContextualVersionConflict error on jupyter notebook #462

Closed
fredjane opened this issue Jul 6, 2023 · 1 comment
Closed

ContextualVersionConflict error on jupyter notebook #462

fredjane opened this issue Jul 6, 2023 · 1 comment
Labels
invalid This doesn't seem right

Comments

@fredjane
Copy link

fredjane commented Jul 6, 2023

I am running a python code on jupyter notebook and I wanted to import and use the specutils package to plot a doppler-shifted spectrum from my data.
This is the part of the code I want to run:

_from astropy.io import ascii
spec1 = ascii.read('NH2CHO_1147_1148.dat') #spectrum data with x = radio velocity [km/s], y = flux [K]
t_mol_s2 = ascii.read('NH2CHO_s1.dat') #Table containing parameters of fitted spectral lines
from specutils import Spectrum1D
print(spec1)
wavelengths = spec1['Velocity']
spectrum = Spectrum1D(spectral_axis=wavelengths, flux=spec1['Flux'])
shift = t_mol_s2['Deltav'][0] #Row in the table containing the shifting quantity for my spectrum
new_spec = Spectrum1D(spectral_axis=spectrum.spectral_axis + shift, flux=spectrum.flux)
print(new_spec)_

and this is the raising error:

_ContextualVersionConflict                 Traceback (most recent call last)
Input In [48], in <cell line: 1>()
----> 1 from specutils import Spectrum1D
      2 print(spec1)
      3 wavelengths = spec1['Velocity']

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/specutils/__init__.py:23, in <module>
     19 test.__test__ = False
     22 # Allow loading spectrum object from top level module
---> 23 from .spectra import *  # noqa
     25 # Load the IO functions
     26 from .io.default_loaders import *  # noqa

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/specutils/spectra/__init__.py:5, in <module>
      1 """
      2 The core specutils data objects package. This contains the
      3 `~astropy.nddata.NDData`-inherited classes used for storing the spectrum data.
      4 """
----> 5 from .spectrum1d import *  # noqa
      6 from .spectral_region import *  # noqa
      7 from .spectrum_collection import *  # noqa

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/specutils/spectra/spectrum1d.py:11, in <module>
      8 from astropy.nddata import NDUncertainty, NDIOMixin, NDArithmeticMixin
     10 from .spectral_axis import SpectralAxis
---> 11 from .spectrum_mixin import OneDSpectrumMixin
     12 from .spectral_region import SpectralRegion
     13 from ..utils.wcs_utils import gwcs_from_array

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/specutils/spectra/spectrum_mixin.py:8, in <module>
      5 from astropy import units as u
      6 from astropy.utils.decorators import deprecated
----> 8 from specutils.utils.wcs_utils import gwcs_from_array
     10 DOPPLER_CONVENTIONS = {}
     11 DOPPLER_CONVENTIONS['radio'] = u.doppler_radio

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/specutils/utils/wcs_utils.py:7, in <module>
      5 from astropy.modeling.models import Shift
      6 from astropy.modeling.tabular import Tabular1D
----> 7 from gwcs import WCS as GWCS
      8 from gwcs import coordinate_frames as cf
     11 def refraction_index(wavelength, method='Griesen2006', co2=None):

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/gwcs/__init__.py:66, in <module>
     63     raise ImportError("GWCS supports Python versions 3.6 and above.")  # pragma: no cover
     65 try:
---> 66     __version__ = get_distribution(__name__).version
     67 except DistributionNotFound:  # pragma: no cover
     68     # package is not installed
     69     pass  # pragma: no cover

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pkg_resources/__init__.py:466, in get_distribution(dist)
    464     dist = Requirement.parse(dist)
    465 if isinstance(dist, Requirement):
--> 466     dist = get_provider(dist)
    467 if not isinstance(dist, Distribution):
    468     raise TypeError("Expected string, Requirement, or Distribution", dist)

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pkg_resources/__init__.py:342, in get_provider(moduleOrReq)
    340 """Return an IResourceProvider for the named module or requirement"""
    341 if isinstance(moduleOrReq, Requirement):
--> 342     return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
    343 try:
    344     module = sys.modules[moduleOrReq]

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pkg_resources/__init__.py:886, in WorkingSet.require(self, *requirements)
    877 def require(self, *requirements):
    878     """Ensure that distributions matching `requirements` are activated
    879 
    880     `requirements` must be a string or a (possibly-nested) sequence
   (...)
    884     included, even if they were already activated in this working set.
    885     """
--> 886     needed = self.resolve(parse_requirements(requirements))
    888     for dist in needed:
    889         self.add(dist)

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pkg_resources/__init__.py:777, in WorkingSet.resolve(self, requirements, env, installer, replace_conflicting, extras)
    774 if dist not in req:
    775     # Oops, the "best" so far conflicts with a dependency
    776     dependent_req = required_by[req]
--> 777     raise VersionConflict(dist, req).with_context(dependent_req)
    779 # push the new requirements onto the stack
    780 new_requirements = dist.requires(req.extras)[::-1]

ContextualVersionConflict: (importlib-metadata 4.11.3 (/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages), Requirement.parse('importlib-metadata>=4.11.4'), {'asdf'})_

I am using a MacBook Air (M1, 2020) with macOS Monterey version 12.3.1 and I have installed python 3.9.7, pip 23.1.2, jupyter notebook 6.4.10 and, looking at pip list, specutils 1.11.0, importlib-metadata 4.11.4 and:
asdf 2.15.0
asdf-astropy 0.4.0
asdf-coordinates-schemas 0.2.0
asdf-standard 1.0.3
asdf-transform-schemas 0.3.0
asdf-unit-schemas 0.1.0
asdf-wcs-schemas 0.1.1

(given that, if I well interpreted the error message, it's the asdf dependency of both import lib-metadata and specutils to raise it)

Can you help me? Thank you in advance.

@jaraco
Copy link
Member

jaraco commented Jul 8, 2023

The ContextualVersionConflict is coming from pkg_resources, which is attempting to validate that "importlib_metadata>=4.11.4" is present as required by "asdf", but importlib_metadata is only available at 4.11.3.

You say you have importlib-metadata 4.11.4 installed, but pkg_resources disagrees. You'll need to install importlib_metadata>=4.11.4 to fix the issue.

This report is not a bug with importlib_metadata and there's nothing this project can do to help with the situation. Please reach out on StackOverflow or other user support for Python packaging for help with your environment.

@jaraco jaraco closed this as completed Jul 8, 2023
@jaraco jaraco added the invalid This doesn't seem right label Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants