0

I am new to Vispy and I want to plot the 2d data with 3 columns in Vispy but my code keeps giving me this error, I even tried
the example code here: example code and it doesn't work, is it a graphic card thing. How to fix it?

return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2575: character maps to <undefined>

Can you tell me how to fix it and what am I missing?

canvas = vispy.scene.SceneCanvas(keys='interactive', show=True)
view = canvas.central_widget.add_view()

# generate data

for X_train, y_train in dataset:
    outputs = model.fit(X_train, y_train)

    centers = torch.normal(size=(50, 3))
    # symbols = np.random.choice(['o', '^'], len(outputs))
    indexes = torch.normal(size=len(outputs), loc=centers.shape[0] / 2,
                               scale=centers.shape[0] / 3)
    indexes = torch.clip(indexes, 0, centers.shape[0] - 1).astype(int)

    # create a scatter object and fill in the data
    scatter = visuals.Markers()
    scatter.set_data(outputs, edge_width=0, face_color=(1, 1, 1, .5), size=5)

    view.add(scatter)

    view.camera = 'turntable'  # or try 'arcball'

    # add a colored 3D axis for orientation
    axis = visuals.XYZAxis(parent=view.scene)
traceback :  Traceback (most recent call last):  \visualization\logs.py", line 2, in <module>
    import vispy.scene \lib\site-packages\vispy\scene\__init__.py", line 33, in <module>
    from .visuals import *  # noqa   \lib\site-packages\vispy\scene\visuals.py", line 18, in <module>
    from .. import visuals \lib\site-packages\vispy\visuals\__init__.py", line 14, in <module>
    from .axis import AxisVisual  # noqa  \lib\site-packages\vispy\visuals\axis.py", line 11, in <module>
    from .visual import CompoundVisual, updating_property  \lib\site-packages\vispy\visuals\visual.py", line 91, in <module>
    from .. import gloo   \lib\site-packages\vispy\gloo\__init__.py", line 47, in <module>
    from . import gl  # noqa   \lib\site-packages\vispy\gloo\gl\__init__.py", line 34, in <module>
    from ._constants import *  # noqa   \lib\site-packages\vispy\gloo\gl\_constants.py", line 330, in <module>
    if repr(ob).startswith('GL_'):   \lib\_sitebuiltins.py", line 61, in __repr__
    self.__setup()   \ib\_sitebuiltins.py", line 51, in __setup
    data = fp.read()   \lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2575: character maps to <undefined>

Process finished with exit code 1

It say there's no vispy.scene although in code provided by Vispy it is stated there

tripleee
  • 175,061
  • 34
  • 275
  • 318
Joseph_
  • 39
  • 6
  • Please dit your question to include the full traceback as it will tell you exactly on what line the error occurs. – Cow Jan 02 '23 at 08:44
  • What is the actual encoding of the file you are attempting to open? It looks vaguely like you have UTF-8 data, or perhaps Latin-1. See also https://meta.stackoverflow.com/questions/379403/problematic-questions-about-decoding-errors – tripleee Jan 02 '23 at 11:20
  • I understand that I should add file = open(filename, encoding="utf8") but where should define this and which filename? because there's no file I'm attempting to open – Joseph_ Jan 02 '23 at 12:06
  • On closer examination, it looks like you have something weird in `\lib\_sitebuiltins.py` - what is this file? – tripleee Jan 03 '23 at 10:49

1 Answers1

0

This is a bug in Python <3.10 that is being triggered by VisPy. You can either update to use Python 3.10+ or wait for the next vispy release where the code that was triggering this has been removed.

See https://github.com/vispy/vispy/issues/2386# for more information.

djhoese
  • 3,567
  • 1
  • 27
  • 45
  • Basically Python can't `repr` it's own copyright or license file if I remember correctly. – djhoese Jan 03 '23 at 15:25
  • it's still not working, would this error be as result of not having a good graphic card? – Joseph_ Jan 06 '23 at 10:54
  • What did you change that isn't working? – djhoese Jan 07 '23 at 14:35
  • sorry for being late. I tried upgrading python but I still get this return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2575: character maps to – Joseph_ Jan 09 '23 at 21:44
  • I tried this, it worked but I don't know what's the next step to do x = open(r"C:\Users\envs\tensor\Lib\site-packages\vispy\gloo\gl\_constants.py", encoding="utf-8", mode="r") print(x.read()) – Joseph_ Jan 09 '23 at 22:06
  • and I did python -c "import check_builtins" I got this which isn'T shown in the link {'__name__': 'builtins', '__doc__': "Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.", '__package__': '', '__loader__': , '__spec__': ModuleSpec(name='builtins', – Joseph_ Jan 09 '23 at 22:58
  • What version of Python are you running now? Note also reading the `gl_constants.py` file isn't the problem. It is the `repr` of the copyright or license that comes with python when running a module. Make sure if you've upgrade Python to 3.10 or newer that you are running your script with that new version. – djhoese Jan 10 '23 at 20:22
  • I got it, can you plse check this question https://stackoverflow.com/questions/75275803/find-the-graph-in-the-network-where-the-clicked-node-belongs-to-in-vispy – Joseph_ Jan 29 '23 at 21:08