Can I install pymc with pip on windows?

I used to use pymc installed with pip on macos. I recently switch to windows system, and tries to get my environment together. I can get pymc installed with pip install pymc. However when I import it, I got following error: UnicodeDecodeError: 'gbk' codec can't decode byte 0xba in position 2367: illegal multibyte sequence. Anyone knows how to fix this?

Here is the entire traceback:

WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\pymc\__init__.py", line 49, in <module>
    from pymc import _version, gp, ode, sampling
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\pymc\gp\__init__.py", line 15, in <module>
    from pymc.gp import cov, mean, util
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\pymc\gp\util.py", line 30, in <module>
    from pymc.distributions.distribution import Distribution
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\pymc\distributions\__init__.py", line 15, in <module>
    from pymc.distributions.bound import Bound
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\pymc\distributions\bound.py", line 23, in <module>
    from pymc.distributions.continuous import BoundedContinuous, bounded_cont_transform
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\pymc\distributions\continuous.py", line 59, in <module>
    from pymc.logprob.abstract import _logcdf_helper, _logprob_helper
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\pymc\logprob\__init__.py", line 37, in <module>
    from pymc.logprob.basic import (
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\pymc\logprob\basic.py", line 65, in <module>
    from pymc.logprob.rewriting import cleanup_ir, construct_ir_fgraph
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\pymc\logprob\rewriting.py", line 84, in <module>
    from pymc.logprob.utils import DiracDelta, indices_from_subtensor
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\pymc\logprob\utils.py", line 67, in <module>
    from pymc.util import makeiter
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\pymc\util.py", line 20, in <module>
    import arviz
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\arviz\__init__.py", line 33, in <module>
    from .data import *
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\arviz\data\__init__.py", line 2, in <module>
    from .base import CoordSpec, DimSpec, dict_to_dataset, numpy_to_data_array
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\arviz\data\base.py", line 20, in <module>
    from .. import __version__, utils
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\arviz\utils.py", line 667, in <module>
    class HtmlTemplate:
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\arviz\utils.py", line 692, in HtmlTemplate
    _, css_style = _load_static_files()  # pylint: disable=protected-access
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\arviz\utils.py", line 662, in _load_static_files
    return [
  File "C:\Users\gabri\AppData\Roaming\Python\Python39\site-packages\arviz\utils.py", line 663, in <listcomp>
    importlib.resources.files("arviz").joinpath(fname).read_text() for fname in STATIC_FILES
  File "C:\Program Files\Python39\lib\pathlib.py", line 1257, in read_text
    return f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xba in position 2367: illegal multibyte sequence

The recommended installation procedure is here. Pip is not recommended because it doesn’t offer all the compiled components (which is why you are getting the BLAS warning). So even if you weren’t getting the error you’re currently getting, sampling would be very slow.

Thanks for the quick reply! I see that the doc said installed through conda, but most of my packages are managed through pip right now. Is there any way I can retrieve all components through pip?

1 Like

You can always install packages via pip when using conda-managed environments. See here.

1 Like

Hi I just encountered the same error. Solved this by downgrading arviz.

mamba install -c conda-forge -n pymc_env arviz=0.15.1

I used mamba, you can use conda as well.

I’ve tried this option. But it seems this problem has nothing to do with the arviz version. I directly changed the encoding to ‘utf-8’ and solved it.

Go to the file of your last traceback and change the encoding by yourself.
i.e. find the pathlib.py, go to line 1257, somewhere says [encoding=encoding], change it to [encoding=‘utf-8’]

I still get this problem even using conda to install.
Following github issue seems related.

Instead of modifying pathlib, i feel it is better to change util.py in arviz directory (Lib\site-packages\arviz\utils.py). Change line 663 to:

importlib.resources.files("arviz").joinpath(fname).read_text(encoding='utf-8') for fname in STATIC_FILES

i.e. add encoding=‘utf-8’ in the parenthesis would work.

1 Like

That appears to be the most recent comment on the relevant arviz issue.

1 Like