使用 pip3 在 macOS 上安装 Metpy

问题描述 投票:0回答:1

我使用 pip3 install metpy 安装了 Metpy。然而,当我尝试使用露点温度的简单示例时,除了错误之外什么也没有得到。这些错误(我认为)与导入语句有关。我正在使用:

import metpy.calc as mpcalc
from metpy.units import units

mixing = 10 * units('g/kg')
print(mixing)

我收到以下错误:

File "/Users/johnbarrett/dewpoint.py", line 1, in <module>
    import metpy.calc as mpcalc
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/metpy/__init__.py", line 13, in <module>
    from .xarray import *  # noqa: F401, F403, E402
    ^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/metpy/xarray.py", line 31, in <module>
    from .units import (_mutate_arguments, DimensionalityError, is_quantity, UndefinedUnitError,
                        units)
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/metpy/units.py", line 26, in <module>
    import pint
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pint/__init__.py", line 18, in <module>
    from .delegates.formatter._format_helpers import formatter
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pint/delegates/__init__.py", line 12, in <module>
    from . import txt_defparser
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pint/delegates/txt_defparser/__init__.py", line 12, in <module>
    from .defparser import DefParser
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pint/delegates/txt_defparser/defparser.py", line 10, in <module>
    from . import block, common, context, defaults, group, plain, system
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pint/delegates/txt_defparser/common.py", line 23, in <module>
    @dataclass(frozen=True)
     ~~~~~~~~~^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/dataclasses.py", line 1295, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
                          frozen, match_args, kw_only, slots,
                          weakref_slot)
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/dataclasses.py", line 1043, in _process_class
    raise TypeError('cannot inherit frozen dataclass from a '
                    'non-frozen one')
TypeError: cannot inherit frozen dataclass from a non-frozen one
➜  ~ python3 dewpoint.py
Traceback (most recent call last):
  File "/Users/johnbarrett/dewpoint.py", line 1, in <module>
    import metpy.calc as mpcalc
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/metpy/__init__.py", line 13, in <module>
    from .xarray import *  # noqa: F401, F403, E402
    ^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/metpy/xarray.py", line 31, in <module>
    from .units import (_mutate_arguments, DimensionalityError, is_quantity, UndefinedUnitError,
                        units)
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/metpy/units.py", line 26, in <module>
    import pint
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pint/__init__.py", line 18, in <module>
    from .delegates.formatter._format_helpers import formatter
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pint/delegates/__init__.py", line 12, in <module>
    from . import txt_defparser
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pint/delegates/txt_defparser/__init__.py", line 12, in <module>
    from .defparser import DefParser
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pint/delegates/txt_defparser/defparser.py", line 10, in <module>
    from . import block, common, context, defaults, group, plain, system
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pint/delegates/txt_defparser/common.py", line 23, in <module>
    @dataclass(frozen=True)
     ~~~~~~~~~^^^^^^^^^^^^^
➜  ~ python3 dewpoint.py
Traceback (most recent call last):
  File "/Users/johnbarrett/dewpoint.py", line 1, in <module>
    import metpy.calc as mpcalc
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/metpy/__init__.py", line 13, in <module>
    from .xarray import *  # noqa: F401, F403, E402
    ^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/metpy/xarray.py", line 31, in <module>
    from .units import (_mutate_arguments, DimensionalityError, is_quantity, UndefinedUnitError,
                        units)
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/metpy/units.py", line 26, in <module>
    import pint
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pint/__init__.py", line 18, in <module>
    from .delegates.formatter._format_helpers import formatter
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pint/delegates/__init__.py", line 12, in <module>
    from . import txt_defparser
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pint/delegates/txt_defparser/__init__.py", line 12, in <module>
    from .defparser import DefParser
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pint/delegates/txt_defparser/defparser.py", line 10, in <module>
    from . import block, common, context, defaults, group, plain, system
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pint/delegates/txt_defparser/common.py", line 23, in <module>
    @dataclass(frozen=True)
     ~~~~~~~~~^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/dataclasses.py", line 1295, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
                          frozen, match_args, kw_only, slots,
                          weakref_slot)
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/dataclasses.py", line 1043, in _process_class
    raise TypeError('cannot inherit frozen dataclass from a '
                    'non-frozen one')
TypeError: cannot inherit frozen dataclass from a non-frozen one

任何帮助将不胜感激, 非常感谢约翰

metpy
1个回答
0
投票

这是 MetPy 用于单位跟踪的当前版本 pint (v0.24.3) 与 Python 3.13 之间的“已知不兼容性”(并且已在 MetPy 问题跟踪器上报告过)。 目前的解决方法是安装并使用 Python 3.12。

© www.soinside.com 2019 - 2024. All rights reserved.