lightweight_mmm
lightweight_mmm copied to clipboard
Error trying to import `.plot`
I am running off of a Google Colab notebook and am trying to follow the code in this article by Mario Filho.
When I try to do
from lightweight_mmm import plot
I get the following error:
---------------------------------------------------------------------------
SystemError Traceback (most recent call last)
[<ipython-input-15-4e3c977dc303>](https://localhost:8080/#) in <module>
----> 1 from lightweight_mmm import plot
12 frames
[/usr/local/lib/python3.8/dist-packages/lightweight_mmm/plot.py](https://localhost:8080/#) in <module>
22 from typing import Any, List, Optional, Sequence, Tuple
23
---> 24 import arviz
25 import jax
26 import jax.numpy as jnp
[/usr/local/lib/python3.8/dist-packages/arviz/__init__.py](https://localhost:8080/#) in <module>
31
32 from .data import *
---> 33 from .plots import *
34 from .plots.backends import *
35 from .stats import *
[/usr/local/lib/python3.8/dist-packages/arviz/plots/__init__.py](https://localhost:8080/#) in <module>
6 from .distcomparisonplot import plot_dist_comparison
7 from .distplot import plot_dist
----> 8 from .elpdplot import plot_elpd
9 from .energyplot import plot_energy
10 from .essplot import plot_ess
[/usr/local/lib/python3.8/dist-packages/arviz/plots/elpdplot.py](https://localhost:8080/#) in <module>
5 from ..data import convert_to_inference_data
6 from ..rcparams import rcParams
----> 7 from ..stats import ELPDData, loo, waic
8 from ..utils import get_coords
9 from .plot_utils import format_coords_as_labels, get_plotting_function
[/usr/local/lib/python3.8/dist-packages/arviz/stats/__init__.py](https://localhost:8080/#) in <module>
2 """Statistical tests and diagnostics for ArviZ."""
3 from .density_utils import *
----> 4 from .diagnostics import *
5 from .stats import *
6 from .stats_refitting import *
[/usr/local/lib/python3.8/dist-packages/arviz/stats/diagnostics.py](https://localhost:8080/#) in <module>
11 from ..utils import Numba, _numba_var, _stack, _var_names
12 from .density_utils import histogram as _histogram
---> 13 from .stats_utils import _circular_standard_deviation, _sqrt
14 from .stats_utils import autocov as _autocov
15 from .stats_utils import not_valid as _not_valid
[/usr/local/lib/python3.8/dist-packages/arviz/stats/stats_utils.py](https://localhost:8080/#) in <module>
531
532 @conditional_vect
--> 533 def _sqrt(a_a, b_b):
534 return (a_a + b_b) ** 0.5
535
[/usr/local/lib/python3.8/dist-packages/arviz/utils.py](https://localhost:8080/#) in conditional_vect(function, **kwargs)
295
296 if function:
--> 297 return wrapper(function)
298 else:
299 return wrapper
[/usr/local/lib/python3.8/dist-packages/arviz/utils.py](https://localhost:8080/#) in wrapper(function)
288 def wrapper(function):
289 try:
--> 290 numba = importlib.import_module("numba")
291 return numba.vectorize(**kwargs)(function)
292
[/usr/lib/python3.8/importlib/__init__.py](https://localhost:8080/#) in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
128
129
[/usr/local/lib/python3.8/dist-packages/numba/__init__.py](https://localhost:8080/#) in <module>
40
41 # Re-export vectorize decorators and the thread layer querying function
---> 42 from numba.np.ufunc import (vectorize, guvectorize, threading_layer,
43 get_num_threads, set_num_threads,
44 set_parallel_chunksize, get_parallel_chunksize,
[/usr/local/lib/python3.8/dist-packages/numba/np/ufunc/__init__.py](https://localhost:8080/#) in <module>
1 # -*- coding: utf-8 -*-
2
----> 3 from numba.np.ufunc.decorators import Vectorize, GUVectorize, vectorize, guvectorize
4 from numba.np.ufunc._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One
5 from numba.np.ufunc import _internal, array_exprs
[/usr/local/lib/python3.8/dist-packages/numba/np/ufunc/decorators.py](https://localhost:8080/#) in <module>
1 import inspect
2
----> 3 from numba.np.ufunc import _internal
4 from numba.np.ufunc.parallel import ParallelUFuncBuilder, ParallelGUFuncBuilder
5
SystemError: initialization of _internal failed without raising an exception
In looking at what happens when I did %pip install lightweight_mmm
I got the following:
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting lightweight_mmm
Downloading lightweight_mmm-0.1.7-py3-none-any.whl (103 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 103.2/103.2 KB 1.1 MB/s eta 0:00:00
Collecting arviz==0.11.2
Downloading arviz-0.11.2-py3-none-any.whl (1.6 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.6/1.6 MB 48.9 MB/s eta 0:00:00
Collecting seaborn==0.11.1
Downloading seaborn-0.11.1-py3-none-any.whl (285 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 285.0/285.0 KB 12.8 MB/s eta 0:00:00
Requirement already satisfied: absl-py in /usr/local/lib/python3.8/dist-packages (from lightweight_mmm) (1.3.0)
Collecting immutabledict>=2.0.0
Downloading immutabledict-2.2.3-py3-none-any.whl (4.0 kB)
Requirement already satisfied: scikit-learn in /usr/local/lib/python3.8/dist-packages (from lightweight_mmm) (1.0.2)
Requirement already satisfied: pandas>=1.1.5 in /usr/local/lib/python3.8/dist-packages (from lightweight_mmm) (1.3.5)
Requirement already satisfied: tensorflow>=2.7.2 in /usr/local/lib/python3.8/dist-packages (from lightweight_mmm) (2.9.2)
Collecting statsmodels>=0.13.0
Downloading statsmodels-0.13.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.9 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9.9/9.9 MB 46.3 MB/s eta 0:00:00
Collecting numpyro>=0.9.2
Downloading numpyro-0.10.1-py3-none-any.whl (292 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 292.7/292.7 KB 11.2 MB/s eta 0:00:00
Collecting matplotlib==3.6.1
Downloading matplotlib-3.6.1-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (9.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9.4/9.4 MB 29.5 MB/s eta 0:00:00
Requirement already satisfied: jaxlib>=0.3.18 in /usr/local/lib/python3.8/dist-packages (from lightweight_mmm) (0.3.25+cuda11.cudnn805)
Collecting numpy>=1.24
Downloading numpy-1.24.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.3/17.3 MB 35.2 MB/s eta 0:00:00
Requirement already satisfied: jax>=0.3.18 in /usr/local/lib/python3.8/dist-packages (from lightweight_mmm) (0.3.25)
Requirement already satisfied: scipy in /usr/local/lib/python3.8/dist-packages (from lightweight_mmm) (1.7.3)
Collecting typing-extensions<4,>=3.7.4.3
Downloading typing_extensions-3.10.0.2-py3-none-any.whl (26 kB)
Requirement already satisfied: netcdf4 in /usr/local/lib/python3.8/dist-packages (from arviz==0.11.2->lightweight_mmm) (1.6.2)
Requirement already satisfied: xarray>=0.16.1 in /usr/local/lib/python3.8/dist-packages (from arviz==0.11.2->lightweight_mmm) (2022.12.0)
Requirement already satisfied: setuptools>=38.4 in /usr/local/lib/python3.8/dist-packages (from arviz==0.11.2->lightweight_mmm) (57.4.0)
Requirement already satisfied: packaging in /usr/local/lib/python3.8/dist-packages (from arviz==0.11.2->lightweight_mmm) (21.3)
Requirement already satisfied: pyparsing>=2.2.1 in /usr/local/lib/python3.8/dist-packages (from matplotlib==3.6.1->lightweight_mmm) (3.0.9)
Collecting contourpy>=1.0.1
Downloading contourpy-1.0.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (300 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 300.0/300.0 KB 6.2 MB/s eta 0:00:00
Collecting fonttools>=4.22.0
Downloading fonttools-4.38.0-py3-none-any.whl (965 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 965.4/965.4 KB 36.0 MB/s eta 0:00:00
Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.8/dist-packages (from matplotlib==3.6.1->lightweight_mmm) (7.1.2)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.8/dist-packages (from matplotlib==3.6.1->lightweight_mmm) (0.11.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.8/dist-packages (from matplotlib==3.6.1->lightweight_mmm) (1.4.4)
Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.8/dist-packages (from matplotlib==3.6.1->lightweight_mmm) (2.8.2)
Requirement already satisfied: opt-einsum in /usr/local/lib/python3.8/dist-packages (from jax>=0.3.18->lightweight_mmm) (3.3.0)
Requirement already satisfied: multipledispatch in /usr/local/lib/python3.8/dist-packages (from numpyro>=0.9.2->lightweight_mmm) (0.6.0)
Requirement already satisfied: tqdm in /usr/local/lib/python3.8/dist-packages (from numpyro>=0.9.2->lightweight_mmm) (4.64.1)
Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.8/dist-packages (from pandas>=1.1.5->lightweight_mmm) (2022.7)
Collecting scipy
Downloading scipy-1.10.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34.5 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 34.5/34.5 MB 14.6 MB/s eta 0:00:00
Requirement already satisfied: patsy>=0.5.2 in /usr/local/lib/python3.8/dist-packages (from statsmodels>=0.13.0->lightweight_mmm) (0.5.3)
Requirement already satisfied: tensorboard<2.10,>=2.9 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (2.9.1)
Requirement already satisfied: protobuf<3.20,>=3.9.2 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (3.19.6)
Requirement already satisfied: keras<2.10.0,>=2.9.0rc0 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (2.9.0)
Requirement already satisfied: flatbuffers<2,>=1.12 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (1.12)
Requirement already satisfied: keras-preprocessing>=1.1.1 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (1.1.2)
Requirement already satisfied: gast<=0.4.0,>=0.2.1 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (0.4.0)
Requirement already satisfied: grpcio<2.0,>=1.24.3 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (1.51.1)
Requirement already satisfied: wrapt>=1.11.0 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (1.14.1)
Requirement already satisfied: google-pasta>=0.1.1 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (0.2.0)
Requirement already satisfied: six>=1.12.0 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (1.15.0)
Requirement already satisfied: tensorflow-estimator<2.10.0,>=2.9.0rc0 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (2.9.0)
Requirement already satisfied: astunparse>=1.6.0 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (1.6.3)
Requirement already satisfied: tensorflow-io-gcs-filesystem>=0.23.1 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (0.29.0)
Requirement already satisfied: termcolor>=1.1.0 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (2.2.0)
Requirement already satisfied: h5py>=2.9.0 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (3.1.0)
Requirement already satisfied: libclang>=13.0.0 in /usr/local/lib/python3.8/dist-packages (from tensorflow>=2.7.2->lightweight_mmm) (15.0.6.1)
Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.8/dist-packages (from scikit-learn->lightweight_mmm) (1.2.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.8/dist-packages (from scikit-learn->lightweight_mmm) (3.1.0)
Requirement already satisfied: wheel<1.0,>=0.23.0 in /usr/local/lib/python3.8/dist-packages (from astunparse>=1.6.0->tensorflow>=2.7.2->lightweight_mmm) (0.38.4)
Requirement already satisfied: requests<3,>=2.21.0 in /usr/local/lib/python3.8/dist-packages (from tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (2.25.1)
Requirement already satisfied: google-auth<3,>=1.6.3 in /usr/local/lib/python3.8/dist-packages (from tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (2.16.0)
Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.8/dist-packages (from tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (3.4.1)
Requirement already satisfied: tensorboard-data-server<0.7.0,>=0.6.0 in /usr/local/lib/python3.8/dist-packages (from tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (0.6.1)
Requirement already satisfied: werkzeug>=1.0.1 in /usr/local/lib/python3.8/dist-packages (from tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (1.0.1)
Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /usr/local/lib/python3.8/dist-packages (from tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (0.4.6)
Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in /usr/local/lib/python3.8/dist-packages (from tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (1.8.1)
Requirement already satisfied: cftime in /usr/local/lib/python3.8/dist-packages (from netcdf4->arviz==0.11.2->lightweight_mmm) (1.6.2)
Requirement already satisfied: cachetools<6.0,>=2.0.0 in /usr/local/lib/python3.8/dist-packages (from google-auth<3,>=1.6.3->tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (5.2.1)
Requirement already satisfied: rsa<5,>=3.1.4 in /usr/local/lib/python3.8/dist-packages (from google-auth<3,>=1.6.3->tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (4.9)
Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.8/dist-packages (from google-auth<3,>=1.6.3->tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (0.2.8)
Requirement already satisfied: requests-oauthlib>=0.7.0 in /usr/local/lib/python3.8/dist-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (1.3.1)
Requirement already satisfied: importlib-metadata>=4.4 in /usr/local/lib/python3.8/dist-packages (from markdown>=2.6.8->tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (6.0.0)
Requirement already satisfied: chardet<5,>=3.0.2 in /usr/local/lib/python3.8/dist-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (4.0.0)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.8/dist-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (1.24.3)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.8/dist-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (2022.12.7)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.8/dist-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (2.10)
Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.8/dist-packages (from importlib-metadata>=4.4->markdown>=2.6.8->tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (3.11.0)
Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in /usr/local/lib/python3.8/dist-packages (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (0.4.8)
Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.8/dist-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.10,>=2.9->tensorflow>=2.7.2->lightweight_mmm) (3.2.2)
Installing collected packages: typing-extensions, numpy, immutabledict, fonttools, scipy, contourpy, statsmodels, matplotlib, seaborn, numpyro, arviz, lightweight_mmm
Attempting uninstall: typing-extensions
Found existing installation: typing_extensions 4.4.0
Uninstalling typing_extensions-4.4.0:
Successfully uninstalled typing_extensions-4.4.0
Attempting uninstall: numpy
Found existing installation: numpy 1.21.6
Uninstalling numpy-1.21.6:
Successfully uninstalled numpy-1.21.6
Attempting uninstall: scipy
Found existing installation: scipy 1.7.3
Uninstalling scipy-1.7.3:
Successfully uninstalled scipy-1.7.3
Attempting uninstall: statsmodels
Found existing installation: statsmodels 0.12.2
Uninstalling statsmodels-0.12.2:
Successfully uninstalled statsmodels-0.12.2
Attempting uninstall: matplotlib
Found existing installation: matplotlib 3.2.2
Uninstalling matplotlib-3.2.2:
Successfully uninstalled matplotlib-3.2.2
Attempting uninstall: seaborn
Found existing installation: seaborn 0.11.2
Uninstalling seaborn-0.11.2:
Successfully uninstalled seaborn-0.11.2
Attempting uninstall: arviz
Found existing installation: arviz 0.12.1
Uninstalling arviz-0.12.1:
Successfully uninstalled arviz-0.12.1
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
pymc 4.1.4 requires arviz>=0.12.0, but you have arviz 0.11.2 which is incompatible.
pydantic 1.10.4 requires typing-extensions>=4.2.0, but you have typing-extensions 3.10.0.2 which is incompatible.
numba 0.56.4 requires numpy<1.24,>=1.18, but you have numpy 1.24.1 which is incompatible.
Successfully installed arviz-0.11.2 contourpy-1.0.7 fonttools-4.38.0 immutabledict-2.2.3 lightweight_mmm-0.1.7 matplotlib-3.6.1 numpy-1.24.1 numpyro-0.10.1 scipy-1.10.0 seaborn-0.11.1 statsmodels-0.13.5 typing-extensions-3.10.0.2
I recognized that this might be similar to the issue as described in #59 with arviz, so I also tried:
!python -m pip uninstall matplotlib
!pip install matplotlib==3.1.3
but I got the same error.
Any suggestions would be greatly appreciated! Thank you!!!
I have found a fix I believe, which I am including here for the sake of documentation. This fix is specific to Google Colab.
The issues seems to be a package problem with numba. So if you downgrade numba on Colab, it will work:
!pip install --upgrade pip
!pip install --upgrade git+https://github.com/google/lightweight_mmm.git
!python -m pip uninstall numba
!pip install numba==0.56.3
(Restart the runtime engine here.)
from lightweight_mmm import lightweight_mmm
from lightweight_mmm import optimize_media
from lightweight_mmm import plot
from lightweight_mmm import preprocessing
from lightweight_mmm import utils
...
After this there are no more import errors on plot
.
I hope this issue and comments are of help to someone.
This worked! Thanks a lot
Thank you. It works for me!
This method could fix the problem temporary however when I'm using poetry to manage the environment it will cause dependencies conflicts. Could we update the dependencies on lightweight-MMM