Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

UnicodeDecodeError when i import arivz #2274

Closed
fish-galaxy opened this issue Aug 10, 2023 · 8 comments · Fixed by #2300
Closed

UnicodeDecodeError when i import arivz #2274

fish-galaxy opened this issue Aug 10, 2023 · 8 comments · Fixed by #2300

Comments

@fish-galaxy
Copy link

fish-galaxy commented Aug 10, 2023

Holle, I want to run:

import arviz

the console return:
  File ~\anaconda3\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File c:\mypy\hann-hydro\ces.py:7
    import arviz as az

  File ~\anaconda3\lib\site-packages\arviz\__init__.py:33
    from .data import *

  File ~\anaconda3\lib\site-packages\arviz\data\__init__.py:2
    from .base import CoordSpec, DimSpec, dict_to_dataset, numpy_to_data_array

  File ~\anaconda3\lib\site-packages\arviz\data\base.py:20
    from .. import __version__, utils

  File ~\anaconda3\lib\site-packages\arviz\utils.py:666
    class HtmlTemplate:

  File ~\anaconda3\lib\site-packages\arviz\utils.py:691 in HtmlTemplate
    _, css_style = _load_static_files()  # pylint: disable=protected-access

  File ~\anaconda3\lib\site-packages\arviz\utils.py:663 in _load_static_files
    return [importlib.resources.files("arviz").joinpath(fname).read_text() for fname in STATIC_FILES]

  File ~\anaconda3\lib\site-packages\arviz\utils.py:663 in <listcomp>
    return [importlib.resources.files("arviz").joinpath(fname).read_text() for fname in STATIC_FILES]

  File ~\anaconda3\lib\pathlib.py:1135 in read_text
    return f.read()

UnicodeDecodeError: 'gbk' codec can't decode byte 0xba in position 2367: illegal multibyte sequence

What do I need to do to solve this problem? Looking forward to your answer!

@ahartikainen
Copy link
Contributor

Hi, what python version and arviz version do you have?

@fish-galaxy
Copy link
Author

I use the version is python 3.10.9 and arviz 0.16.1

@sethaxen
Copy link
Member

This looks very similar, perhaps identical, to an issue that came up in CI when wrapping arviz with Julia (JuliaRegistries/General#88578 (comment)). Note that the error traces back to the same line of Python code: https://github.com/JuliaRegistries/General/actions/runs/5808545587/job/15745534758#step:16:885 . This was with a fresh Conda environment built with micromamba with only the constraint "arviz >= 0.14.0".

@vitwei
Copy link

vitwei commented Aug 11, 2023

similar question
UnicodeDecodeError: 'gbk' codec can't decode byte 0xba in position 2367: illegal multibyte sequence

import arviz
Traceback (most recent call last):
File "", line 1, in
File "D:\anacoda\envs\pymc4\Lib\site-packages\arviz_init_.py", line 33, in
from .data import *
File "D:\anacoda\envs\pymc4\Lib\site-packages\arviz\data_init_.py", line 2, in
from .base import CoordSpec, DimSpec, dict_to_dataset, numpy_to_data_array
File "D:\anacoda\envs\pymc4\Lib\site-packages\arviz\data\base.py", line 20, in
from .. import version, utils
File "D:\anacoda\envs\pymc4\Lib\site-packages\arviz\utils.py", line 667, in
class HtmlTemplate:
File "D:\anacoda\envs\pymc4\Lib\site-packages\arviz\utils.py", line 692, in HtmlTemplate
_, css_style = _load_static_files() # pylint: disable=protected-access
^^^^^^^^^^^^^^^^^^^^
File "D:\anacoda\envs\pymc4\Lib\site-packages\arviz\utils.py", line 662, in _load_static_files
return [
^
File "D:\anacoda\envs\pymc4\Lib\site-packages\arviz\utils.py", line 663, in
importlib.resources.files("arviz").joinpath(fname).read_text() for fname in STATIC_FILES
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\anacoda\envs\pymc4\Lib\pathlib.py", line 1059, in read_text
return f.read()
^^^^^^^^
UnicodeDecodeError: 'gbk' codec can't decode byte 0xba in position 2367: illegal multibyte sequence

python 3.11.4
arivz 0.16.0

using arivz 0.15 non error

@fish-galaxy
Copy link
Author

@sethaxen Thanks, i find arviz can successfully run if the version<0.16.0 when i try to change the version.
@vitwei You can try to ues the arviz0.15.1 or lower version.

@ahartikainen
Copy link
Contributor

How did you install arviz?

Conda or pip?

@lucianopaz
Copy link
Contributor

This also came up here. The issue there was that the user was on windows. The system encoding there isn't utf-8, if I remember correctly it's Latin1, so when they try to read the contents of the file that has utf-8 special characters, the system level encoding can't understand them and errors out. To fix that, you'll need to explicitly pass encoding="utf-8" when calling read_text.

@OriolAbril
Copy link
Member

We need to add the encoding argument in

importlib.resources.files("arviz").joinpath(fname).read_text() for fname in STATIC_FILES
then. Thanks @lucianopaz!

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants