EconForge / dolo.py

Economic modelling in python
BSD 2-Clause "Simplified" License
98 stars 72 forks source link

Issue reading grammar on Windows #233

Closed Mv77 closed 2 years ago

Mv77 commented 2 years ago

Hi,

I'm trying to work with dolo in my Windows machine, but the latest version (0.4.9.15) does not work. Running import dolo causes the following error

>>> import dolo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\mateo\Anaconda3\lib\site-packages\dolo\__init__.py", line 3, in <module>
    import dolang
  File "C:\Users\mateo\Anaconda3\lib\site-packages\dolang\__init__.py", line 4, in <module>
    from dolang.grammar import parse_string
  File "C:\Users\mateo\Anaconda3\lib\site-packages\dolang\grammar.py", line 29, in <module>
    grammar_0 = open(DATA_PATH, "rt").read()
  File "C:\Users\mateo\Anaconda3\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 1179: character maps to <undefined>

What seems to be happening is that Windows tries to open the grammar file using the encoding cp1252 by default, and there is a character (0x9d) that is not found. I wonder if there is a way to impose an encoding that would work, say open(DATA_PATH, "rt",encoding = "utf-8")

albop commented 2 years ago

Yes, that's probably what's happening. I thought I had fixed that one a while ago (in dolang) : https://github.com/EconForge/dolang.py/blob/master/dolang/grammar.py

Can you check the version of dolang you are using and if it is not 0.15, try to update it ?

Le lun. 1 nov. 2021 à 19:50, Mateo Velásquez-Giraldo < @.***> a écrit :

Hi,

I'm trying to work with dolo in my Windows machine, but the latest version (0.4.9.15) does not work. Running import dolo causes the following error

import dolo Traceback (most recent call last): File "", line 1, in File "C:\Users\mateo\Anaconda3\lib\site-packages\dolo__init.py", line 3, in import dolang File "C:\Users\mateo\Anaconda3\lib\site-packages\dolang\init__.py", line 4, in from dolang.grammar import parse_string File "C:\Users\mateo\Anaconda3\lib\site-packages\dolang\grammar.py", line 29, in grammar_0 = open(DATA_PATH, "rt").read() File "C:\Users\mateo\Anaconda3\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 1179: character maps to

What seems to be happening is that Windows tries to open the grammar file using the encoding cp1252 by default, and there is a character (0x9d) that is not found. I wonder if there is a way to impose an encoding that would work, say open(DATA_PATH, "rt",encoding = "utf-8")

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/EconForge/dolo.py/issues/233, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACDSKOCAHOPRXRPMESYZHLUJ3OOZANCNFSM5HEVYNLA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Mv77 commented 2 years ago

Updating to 0.15 did fix the issue, thanks @albop.

For some reason pip install dolo is installing dolang==0.0.14 for me. Did not know .15 was out. Thanks again!