1

After installing ArviZ in the obvious way (conda install -c conda-forge arviz), I get the following failure. If anyone could shed light on what to do to fix this, that would be great.

>>> import arviz as az
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/igor/anaconda3/lib/python3.7/site-packages/arviz/__init__.py", line 32, in <module>
from .data import *
  File "/Users/igor/anaconda3/lib/python3.7/site-packages/arviz/data/__init__.py", line 2, in <module>
from .base import CoordSpec, DimSpec, dict_to_dataset, numpy_to_data_array
  File "/Users/igor/anaconda3/lib/python3.7/site-packages/arviz/data/base.py", line 10, in <module>
import xarray as xr
  File "/Users/igor/anaconda3/lib/python3.7/site-packages/xarray/__init__.py", line 3, in <module>
from . import testing, tutorial, ufuncs
 File "/Users/igor/anaconda3/lib/python3.7/site-packages/xarray/testing.py", line 8, in <module>
from xarray.core import duck_array_ops, formatting, utils
  File "/Users/igor/anaconda3/lib/python3.7/site-packages/xarray/core/duck_array_ops.py", line 15, in <module>
from . import dask_array_compat, dask_array_ops, dtypes, npcompat, nputils
  File "/Users/igor/anaconda3/lib/python3.7/site-packages/xarray/core/dask_array_compat.py", line 5, in <module>
from .pycompat import dask_version
  File "/Users/igor/anaconda3/lib/python3.7/site-packages/xarray/core/pycompat.py", line 55, in <module>
    dsk = DuckArrayModule("dask")
  File "/Users/igor/anaconda3/lib/python3.7/site-packages/xarray/core/pycompat.py", line 25, in __init__
duck_array_type = (import_module("dask.array").Array,)
  File "/Users/igor/anaconda3/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "/Users/igor/anaconda3/lib/python3.7/site-packages/dask/array/__init__.py", line 3, in <module>
from . import backends, fft, lib, linalg, ma, overlap, random
  File "/Users/igor/anaconda3/lib/python3.7/site-packages/dask/array/fft.py", line 13, in <module>
from .core import concatenate as _concatenate
  File "/Users/igor/anaconda3/lib/python3.7/site-packages/dask/array/core.py", line 20, in <module>
from fsspec import get_mapper
  File "/Users/igor/anaconda3/lib/python3.7/site-packages/fsspec/__init__.py", line 13, in <module>
from .core import get_fs_token_paths, open, open_files, open_local
   File "/Users/igor/anaconda3/lib/python3.7/site-packages/fsspec/core.py", line 18, in <module>
from .compression import compr
  File "/Users/igor/anaconda3/lib/python3.7/site-packages/fsspec/compression.py", line 139, in <module>
snappy.compress
AttributeError: module 'snappy' has no attribute 'compress'

Following the suggestion of @merv, I get the following, which explains the problem (it is a different package called snappy, for computational topology). But how do I fix it (the obvious solution is to have a different environment, but I am a bit puzzled as to how it is possible to have two pypi packages with the same name to begin with.

# packages in environment at /Users/igor/anaconda3:
#
# Name                    Version            Build           Channel
arviz                     0.11.2             pyhd8
dask                      2021.8.0           pyhd3eb1b0_0  
dask-core                 2021.8.0           pyhd3eb1b0_0  
fsspec                    2021.7.0           pyhd3eb1b0_0  
snappy                    3.0.1                    pypi_0    pypi
snappy-15-knots           1.1                      pypi_0    pypi
snappy-manifolds          1.1.2                    pypi_0    pypi
xarray                    0.19.0             pyhd3eb1b0_1  
merv
  • 67,214
  • 13
  • 180
  • 245
Igor Rivin
  • 4,632
  • 2
  • 23
  • 35
  • Maybe try updating some of the packages in the stack trace. E.g., `python-snappy`, `fsspec`, `xarray`, `dask`. – merv Aug 25 '21 at 16:59
  • @merv I do a conda update pretty much daily... – Igor Rivin Aug 25 '21 at 17:36
  • Okay. Could you please add the output of `conda list '(snappy|fsspec|xarray|dask|arviz)'` to the question, so we know what versions/builds/channels are used? – merv Aug 25 '21 at 17:57
  • @merv you are a wise man. See the edit. – Igor Rivin Aug 26 '21 at 02:12
  • Oh, that sucks. Yeah, new environment. Technically, they don't have the same package name: `snappy` is the topology lib; `python-snappy` is the wrapper for Google's compression lib. That allows them to coexist in PyPA. However, they export modules into the same namespace `snappy`, which is problematic. I suspect there should be a duplicate question somewhere, but I mostly just see questions about namespacing their own modules, not what to do when public packages collide. – merv Aug 26 '21 at 16:24

1 Answers1

2

Looking at the installed packages, you don't have python-snappy installed. I just verified that installing it seems to get it working, although you are right that technically python-snappy and snappy are colliding into the module namespace snappy.

conda install python-snappy

or

pip install python-snappy

As you mentioned, it might be better to simply use a new environment, and avoid having snappy and python-snappy installed in the same one.

merv
  • 67,214
  • 13
  • 180
  • 245