Search code examples
pythonpint

Spectrochempy Unable to Find "pint.unit" -- Module Not Found Error


I am trying to install spectrochempy (https://www.spectrochempy.fr/stable/gettingstarted/install/install_win.html) via conda on Windows 10. I am able to follow the instructions without an error message; it is only when trying to verify the installation that I get an error message. The full text of the error message is attached below.

Question: How do I make sure the missing packages are installed and which steps can I take to ensure a smooth installation?

Full error message:

from spectrochempy import *
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-eda726baf6bc> in <cell line: 1>()
----> 1 from spectrochempy import *

~\anaconda3\lib\site-packages\spectrochempy\__init__.py in <module>
     57 # import the main api
     58
---> 59 from spectrochempy import api
     60 from spectrochempy.api import *  # noqa: F401
     61

~\anaconda3\lib\site-packages\spectrochempy\api.py in <module>
     86 # ------------------------------------------------------------------
     87 # import the core api
---> 88 from . import core
     89 from .core import *  # noqa: F403, F401, E402
     90

~\anaconda3\lib\site-packages\spectrochempy\core\__init__.py in <module>
     29 # ======================================================================================================================
     30
---> 31 from ..utils import pstr  # noqa: E402
     32 import logging
     33 import inspect

~\anaconda3\lib\site-packages\spectrochempy\utils\__init__.py in <module>
     28 from .print import *
     29 from .file import *
---> 30 from .jsonutils import *
     31 from .misc import *
     32 from .packages import *

~\anaconda3\lib\site-packages\spectrochempy\utils\jsonutils.py in <module>
     18 import numpy as np
     19
---> 20 from spectrochempy.core.units import Quantity, Unit
     21
     22 __all__ = ["json_serialiser", "json_decoder"]

~\anaconda3\lib\site-packages\spectrochempy\core\units\__init__.py in <module>
     10 """
     11
---> 12 from .units import *  # noqa: F403, F401, E402

~\anaconda3\lib\site-packages\spectrochempy\core\units\units.py in <module>
     30
     31
---> 32 from pint.unit import UnitsContainer, Unit, UnitDefinition
     33 from pint.quantity import Quantity
     34 from pint.formatting import siunitx_format_unit

ModuleNotFoundError: No module named 'pint.unit'

What I've tried:

0. "restart PC"

1. "conda update conda" C:\WINDOWS\system32>conda update conda Collecting package metadata (current_repodata.json): done Solving environment: done #All requested packages already installed. Retrieving notices: ...working... done

2. "conda install pint" / "conda update pint" C:\WINDOWS\system32>conda install pint Collecting package metadata (current_repodata.json): done Solving environment: done #All requested packages already installed. Retrieving notices: ...working... done

Note: I can run "In [1]: from pint import *" without a problem but "In [2]: from spectrochempy import *" will still claim "ModuleNotFoundError: No module named 'pint.unit'"

3. Re-install Python I've uninstalled each instance of python I could find in "add or remove programs", then, I deleted "C:\Users\USERNAME\AppData\Local\Programs\Python"; lastly, I removed python from my PATH. After all of that, I installed a fresh python 3.9.13 using Anaconda.


Solution

  • For Future Reference: The solution was to downgrade pint 0.20 -> 0.19

    This has turned out to be a bug in the spectrochempy code. There is a thread on github (https://github.com/spectrochempy/spectrochempy/issues/490) which alleges this issue is already solved, however, this was still an issue for me. I used pip to do this which may not have been best practice but worked for me in this case:

    pip uninstall pint
    
    pip install pint=0.19.2