Installation and import error of pymc5

Hello, I installed pymc5 using conda-forge.
but I have suffering the error when importing pymc

The error is :
UnicodeDecodeError: ‘cp949’ codec can’t decode byte 0xe2 in position 2365: illegal multibyte sequence

Please help me…

Can you past the entire error message and trace?

UnicodeDecodeError                        Traceback (most recent call last)
Cell In[1], line 1
----> 1 import pymc as pm
      2 import numpy as np
      4 # Example data

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\pymc\__init__.py:49
     44     pytensor.config.gcc__cxxflags = augmented
     47 __set_compiler_flags()
---> 49 from pymc import _version, gp, ode, sampling
     50 from pymc.backends import *
     51 from pymc.blocking import *

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\pymc\gp\__init__.py:15
      1 #   Copyright 2023 The PyMC Developers
      2 #
      3 #   Licensed under the Apache License, Version 2.0 (the "License");
   (...)
     12 #   See the License for the specific language governing permissions and
     13 #   limitations under the License.
---> 15 from pymc.gp import cov, mean, util
     16 from pymc.gp.gp import (
     17     TP,
     18     Latent,
   (...)
     23     MarginalSparse,
     24 )
     25 from pymc.gp.hsgp_approx import HSGP

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\pymc\gp\util.py:30
     27 from scipy.cluster.vq import kmeans
     29 # Avoid circular dependency when importing modelcontext
---> 30 from pymc.distributions.distribution import Distribution
     31 from pymc.model import modelcontext
     32 from pymc.pytensorf import compile_pymc, walk_model

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\pymc\distributions\__init__.py:15
      1 #   Copyright 2023 The PyMC Developers
      2 #
      3 #   Licensed under the Apache License, Version 2.0 (the "License");
   (...)
     12 #   See the License for the specific language governing permissions and
     13 #   limitations under the License.
---> 15 from pymc.distributions.bound import Bound
     16 from pymc.distributions.censored import Censored
     17 from pymc.distributions.continuous import (
     18     AsymmetricLaplace,
     19     Beta,
   (...)
     51     Weibull,
     52 )

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\pymc\distributions\bound.py:23
     20 from pytensor.tensor.random.op import RandomVariable
     21 from pytensor.tensor.var import TensorVariable
---> 23 from pymc.distributions.continuous import BoundedContinuous, bounded_cont_transform
     24 from pymc.distributions.dist_math import check_parameters
     25 from pymc.distributions.distribution import Continuous, Discrete

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\pymc\distributions\continuous.py:59
     56 from pytensor.tensor.random.op import RandomVariable
     57 from pytensor.tensor.var import TensorConstant
---> 59 from pymc.logprob.abstract import _logcdf_helper, _logprob_helper
     60 from pymc.logprob.basic import icdf
     62 try:

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\pymc\logprob\__init__.py:37
      1 #   Copyright 2023 The PyMC Developers
      2 #
      3 #   Licensed under the Apache License, Version 2.0 (the "License");
   (...)
     34 #   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     35 #   SOFTWARE.
---> 37 from pymc.logprob.basic import (
     38     conditional_logp,
     39     icdf,
     40     logcdf,
     41     logp,
     42     transformed_conditional_logp,
     43 )
     45 # isort: off
     46 # Add rewrites to the DBs
     47 import pymc.logprob.binary

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\pymc\logprob\basic.py:65
     56 from typing_extensions import TypeAlias
     58 from pymc.logprob.abstract import (
     59     MeasurableVariable,
     60     _icdf_helper,
   (...)
     63     _logprob_helper,
     64 )
---> 65 from pymc.logprob.rewriting import cleanup_ir, construct_ir_fgraph
     66 from pymc.logprob.transforms import RVTransform, TransformValuesRewrite
     67 from pymc.logprob.utils import find_rvs_in_graph, rvs_to_value_vars

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\pymc\logprob\rewriting.py:84
     81 from pytensor.tensor.var import TensorVariable
     83 from pymc.logprob.abstract import MeasurableVariable
---> 84 from pymc.logprob.utils import DiracDelta, indices_from_subtensor
     86 inc_subtensor_ops = (IncSubtensor, AdvancedIncSubtensor, AdvancedIncSubtensor1)
     87 subtensor_ops = (AdvancedSubtensor, AdvancedSubtensor1, Subtensor)

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\pymc\logprob\utils.py:67
     64 from pytensor.tensor.var import TensorVariable
     66 from pymc.logprob.abstract import MeasurableVariable, _logprob
---> 67 from pymc.util import makeiter
     70 def walk_model(
     71     graphs: Iterable[TensorVariable],
     72     walk_past_rvs: bool = False,
     73     stop_at_vars: Optional[Set[TensorVariable]] = None,
     74     expand_fn: Callable[[TensorVariable], List[TensorVariable]] = lambda var: [],
     75 ) -> Generator[TensorVariable, None, None]:
     76     """Walk model graphs and yield their nodes.
     77 
     78     By default, these walks will not go past ``MeasurableVariable`` nodes.
   (...)
     89         A function that returns the next variable(s) to be traversed.
     90     """

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\pymc\util.py:20
     16 import warnings
     18 from typing import Any, Dict, List, Optional, Sequence, Tuple, Union, cast
---> 20 import arviz
     21 import cloudpickle
     22 import numpy as np

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\arviz\__init__.py:33
     27         super()._log(level, msg, *args, **kwargs)
     30 _log = Logger("arviz")
---> 33 from .data import *
     34 from .plots import *
     35 from .plots.backends import *

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\arviz\data\__init__.py:2
      1 """Code for loading and manipulating data structures."""
----> 2 from .base import CoordSpec, DimSpec, dict_to_dataset, numpy_to_data_array
      3 from .converters import convert_to_dataset, convert_to_inference_data
      4 from .datasets import clear_data_home, list_datasets, load_arviz_data

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\arviz\data\base.py:20
     15 except ImportError:
     16     # mypy struggles with conditional imports expressed as catching ImportError:
     17     # https://github.com/python/mypy/issues/1153
     18     import json  # type: ignore
---> 20 from .. import __version__, utils
     21 from ..rcparams import rcParams
     23 CoordSpec = Dict[str, List[Any]]

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\arviz\utils.py:667
    658     """Lazily load the resource files into memory the first time they are needed.
    659 
    660     Clone from xarray.core.formatted_html_template.
    661     """
    662     return [
    663         importlib.resources.files("arviz").joinpath(fname).read_text() for fname in STATIC_FILES
    664     ]
--> 667 class HtmlTemplate:
    668     """Contain html templates for InferenceData repr."""
    670     html_template = """
    671             <div>
    672               <div class='xr-header'>
   (...)
    678             </div>
    679             """

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\arviz\utils.py:692, in HtmlTemplate()
    670 html_template = """
    671         <div>
    672           <div class='xr-header'>
   (...)
    678         </div>
    679         """
    680 element_template = """
    681         <li class = "xr-section-item">
    682               <input id="idata_{group_id}" class="xr-section-summary-in" type="checkbox">
   (...)
    690         </li>
    691         """
--> 692 _, css_style = _load_static_files()  # pylint: disable=protected-access
    693 specific_style = ".xr-wrap{width:700px!important;}"
    694 css_template = f"<style> {css_style}{specific_style} </style>"

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\arviz\utils.py:662, in _load_static_files()
    656 @lru_cache(None)
    657 def _load_static_files():
    658     """Lazily load the resource files into memory the first time they are needed.
    659 
    660     Clone from xarray.core.formatted_html_template.
    661     """
--> 662     return [
    663         importlib.resources.files("arviz").joinpath(fname).read_text() for fname in STATIC_FILES
    664     ]

File ~\anaconda3\envs\BayesianBox\Lib\site-packages\arviz\utils.py:663, in <listcomp>(.0)
    656 @lru_cache(None)
    657 def _load_static_files():
    658     """Lazily load the resource files into memory the first time they are needed.
    659 
    660     Clone from xarray.core.formatted_html_template.
    661     """
    662     return [
--> 663         importlib.resources.files("arviz").joinpath(fname).read_text() for fname in STATIC_FILES
    664     ]

File ~\anaconda3\envs\BayesianBox\Lib\pathlib.py:1059, in Path.read_text(self, encoding, errors)
   1057 encoding = io.text_encoding(encoding)
   1058 with self.open(mode='r', encoding=encoding, errors=errors) as f:
-> 1059     return f.read()

UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 2365: illegal multibyte sequence

Seems like an arviz problem. Any clue @OriolAbril ? Did you install via the instructions found here?

Have you installed everything via conda forge? If so, are you able to import arviz alone directly? And xarray?

That is, run first import arviz if it doesn’t work, import xarray.

If neither work. Could you try installing only xarray first, see if you can import it, then arviz also see if importable?

1 Like

I changed encoding option of pathlib.py and configparser.py in virtual environment!
It works well.

1 Like

the same problem. could you tell me how to change the encoding option?

If you run the pymc code with inadequacy installation, you can find error in pathlib.py and configparser.py.
In my case, I changed encoding=‘utf-8’.

Yes, it’s solved after changing to ‘utf-8’, thanks a lot.

1 Like