1

I am trying to use kats for the first time in order to run the code of this article

However I had the same error as in this question and in this question so I tried to solve it with the answers on those question. (I was using Python 3.6 and now I am using python 3.9)

However now I have a different error, and even harder to google. Now it is

from kats.detectors.outlier import OutlierDetector
outlier_detector = OutlierDetector(ts_day, "additive")

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[19], line 1
----> 1 from kats.detectors.outlier import OutlierDetector
      3 outlier_detector = OutlierDetector(ts_day, "additive")

File ~/miniconda3/envs/data_analysisPy39/lib/python3.9/site-packages/kats/__init__.py:6
      1 # Copyright (c) Meta Platforms, Inc. and affiliates.
      2 #
      3 # This source code is licensed under the MIT license found in the
      4 # LICENSE file in the root directory of this source tree.
----> 6 from . import compat  # noqa # usort: skip
      7 from . import consts  # noqa # usort: skip
      8 from . import data  # noqa # usort: skip

File ~/miniconda3/envs/data_analysisPy39/lib/python3.9/site-packages/kats/compat/__init__.py:6
      1 # Copyright (c) Meta Platforms, Inc. and affiliates.
      2 #
      3 # This source code is licensed under the MIT license found in the
      4 # LICENSE file in the root directory of this source tree.
----> 6 from . import compat  # noqa # usort: skip
      7 from . import pandas  # noqa # usort: skip
      8 from . import statsmodels  # noqa # usort: skip

File ~/miniconda3/envs/data_analysisPy39/lib/python3.9/site-packages/kats/compat/compat.py:19
     14 from typing import Callable, Union
     16 from packaging import version as pv
---> 19 V = Union[str, "Version", pv.Version, pv.LegacyVersion]
     22 class Version:
     23     """Extend packaging Version to allow comparing to version strings.
     24 
     25     Wraps instead of extends, because pv.parse can return either a
     26     pv.Version or a pv.LegacyVersion.
     27     """

AttributeError: module 'packaging.version' has no attribute 'LegacyVersion'

Has anyone been able to run kats successfully? How can this error be corrected?

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150

1 Answers1

1

Yesterday I used Kats for the first time and I had the same problem.

Reason: The new version of the package packaging (22.0) removed the attribute LegacyVersion recently (2022-12-07). Found inspiration on this webpage: Webpage01

My solution = Change version 22.0 of packaging to 21.3

Launch Anaconda Navigator; Select your environment; Select the package packaging: [enter image description here]

Click on the green tick mark and then move down to the option "Mark for specific version of installation" and choose the version that is required (21.3), click on Apply. [enter image description here]

Confirm.

The new version is installed: [enter image description here]

Result: The line of code “from kats.consts import TimeSeriesData” in the aforementioned article is now executed without problems.

XuMuK
  • 564
  • 4
  • 11
  • 32
MiracleMan
  • 11
  • 1