nomad-coe / nomad

NOMAD lets you manage and share your materials science data in a way that makes it truly useful to you, your group, and the community.
https://nomad-lab.eu
Apache License 2.0
64 stars 14 forks source link

JOSS Review: Google Colab (Python 3.8) -- importing `ArchiveQuery` gives `ContextualVersionConflict` for `wrapt` #70

Closed sgbaird closed 11 months ago

sgbaird commented 1 year ago

Colab Reproducer

Similar to #69, this is for Python 3.8 on Colab, but I'm leaving it here since I gave it a try.

---------------------------------------------------------------------------
ContextualVersionConflict                 Traceback (most recent call last)
[<ipython-input-3-b4e3e3a957d0>](https://localhost:8080/#) in <cell line: 1>()
----> 1 from nomad.client.archive import ArchiveQuery
      2 
      3 query = ArchiveQuery(query={}, required={}, page_size=10, results_max=10000)

8 frames
[/usr/local/lib/python3.10/dist-packages/nomad/client/__init__.py](https://localhost:8080/#) in <module>
     17 #
     18 
---> 19 from .archive import ArchiveQuery
     20 from .api import Auth
     21 from .upload import upload_file

[/usr/local/lib/python3.10/dist-packages/nomad/client/archive.py](https://localhost:8080/#) in <module>
     26 from keycloak import KeycloakOpenID
     27 
---> 28 from nomad import config, metainfo as mi
     29 from nomad.datamodel import EntryArchive, ClientContext
     30 

[/usr/local/lib/python3.10/dist-packages/nomad/config/__init__.py](https://localhost:8080/#) in <module>
     40 from typing import List, Any, Union
     41 
---> 42 from nomad.config.models import (
     43     NomadSettings, Services, Meta, Oasis, NORTH, RabbitMQ, Celery, FS, Elastic, Keycloak, Mongo, Logstash, Tests, Mail, Normalize, Resources, Client, DataCite, GitLab, Process, Reprocess, RFC3161Timestamp, BundleExport, BundleImport, Archive, UI
     44 )

[/usr/local/lib/python3.10/dist-packages/nomad/config/models.py](https://localhost:8080/#) in <module>
     27 from pkg_resources import get_distribution, DistributionNotFound
     28 try:
---> 29     __version__ = get_distribution('nomad-lab').version
     30 except DistributionNotFound:
     31     # package is not installed

[/usr/local/lib/python3.10/dist-packages/pkg_resources/__init__.py](https://localhost:8080/#) in get_distribution(dist)
    524         dist = Requirement.parse(dist)
    525     if isinstance(dist, Requirement):
--> 526         dist = get_provider(dist)
    527     if not isinstance(dist, Distribution):
    528         raise TypeError("Expected string, Requirement, or Distribution", dist)

[/usr/local/lib/python3.10/dist-packages/pkg_resources/__init__.py](https://localhost:8080/#) in get_provider(moduleOrReq)
    396     """Return an IResourceProvider for the named module or requirement"""
    397     if isinstance(moduleOrReq, Requirement):
--> 398         return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
    399     try:
    400         module = sys.modules[moduleOrReq]

[/usr/local/lib/python3.10/dist-packages/pkg_resources/__init__.py](https://localhost:8080/#) in require(self, *requirements)
    964         included, even if they were already activated in this working set.
    965         """
--> 966         needed = self.resolve(parse_requirements(requirements))
    967 
    968         for dist in needed:

[/usr/local/lib/python3.10/dist-packages/pkg_resources/__init__.py](https://localhost:8080/#) in resolve(self, requirements, env, installer, replace_conflicting, extras)
    825                 continue
    826 
--> 827             dist = self._resolve_dist(
    828                 req, best, replace_conflicting, env, installer, required_by, to_activate
    829             )

[/usr/local/lib/python3.10/dist-packages/pkg_resources/__init__.py](https://localhost:8080/#) in _resolve_dist(self, req, best, replace_conflicting, env, installer, required_by, to_activate)
    871             # Oops, the "best" so far conflicts with a dependency
    872             dependent_req = required_by[req]
--> 873             raise VersionConflict(dist, req).with_context(dependent_req)
    874         return dist
    875 

ContextualVersionConflict: (wrapt 1.14.1 (/usr/local/lib/python3.10/dist-packages), Requirement.parse('wrapt~=1.12.1'), {'nomad-lab'})
markus1978 commented 1 year ago

Let's treat this as a duplicate of #69 for now.

markus1978 commented 1 year ago

When I run this with a newer Python version on Colab (Python 3.10.x), I not surprisingly run into #68.

markus1978 commented 1 year ago

To get rid of the ContextualVersionConflict: (wrapt 1.14.1, please install pip install wrapt==1.14.1 and restart the runtime.

This happens when the Python runtime already imported one version of a package and now after installing nomad-lab and thereby changing the version and now trying to import this other version. Forcing the install of wrapt==1.14.1 after installing nomad-lab and getting a fresh Python runtime allows to work around this.

zhubonan commented 1 year ago

Just so GitHub knows - this is related to: https://github.com/openjournals/joss-reviews/issues/5388

markus1978 commented 11 months ago

We now released nomad-lab==1.2.0 to PyPI. This package can be installed to google codelab without any of the tricks above. Here is an example notebook: https://colab.research.google.com/drive/1Zlf24eAxFiqtIGbp5NLm66vQR8QPt3AM?usp=sharing.