EconForge / dolo.py

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

Problem importing dolo " 'charmap' codec can't decode byt" #223

Open marcdelabarrera opened 3 years ago

marcdelabarrera commented 3 years ago

I have installed dolo (0.4.9.14) on a Windows but when I import dolo, the following error arises:

~\anaconda3\lib\encodings\cp1252.py in decode(self, input, final)
     21 class IncrementalDecoder(codecs.IncrementalDecoder):
     22     def decode(self, input, final=False):
---> 23         return codecs.charmap_decode(input,self.errors,decoding_table)[0]
     24 
     25 class StreamWriter(Codec,codecs.StreamWriter):

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1179: character maps to <undefined>

Any idea why this might be happening?

albop commented 3 years ago

hmm, can you tell me more about your conda environment ? most importantly the python version ?

On Fri, Feb 19, 2021 at 12:13 AM marcdelabarrera notifications@github.com wrote:

I have installed dolo (0.4.9.14) on a Windows but when I import dolo, the following error arises:

~\anaconda3\lib\encodings\cp1252.py in decode(self, input, final) 21 class IncrementalDecoder(codecs.IncrementalDecoder): 22 def decode(self, input, final=False): ---> 23 return codecs.charmap_decode(input,self.errors,decoding_table)[0] 24 25 class StreamWriter(Codec,codecs.StreamWriter):

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1179: character maps to

Any idea why this might be happening?

— 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/223, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACDSKKVD4V7LIS5GOQKXYLS7WNINANCNFSM4X3KHAEQ .

marcdelabarrera commented 3 years ago

Thank you for quick reply Pablo. I am using anaconda on a windows, with Pyhon 3.7.6. I don't want to get back to Dynare!

Also, I tried to install it on Google Colab, I could import it, but when I try to run your first example

model = yaml_import("https://raw.githubusercontent.com/EconForge/dolo/master/examples/models/rbc.yaml")

I get the error

/usr/local/lib/python3.6/dist-packages/dolo/linter.py in check_definitions(data)
    275 
    276     new_definitions = dict()
--> 277     for k, v in definitions.items():
    278         pos = definitions.lc.data[k]
    279         if k in known_symbols:

AttributeError: 'LiteralScalarString' object has no attribute 'items'
albop commented 3 years ago

Hi @marcdelabarrera, There are two different issues here:

cohenimhuji commented 3 years ago

Hi, i installed dolo (dolo-0.4.9.14.dist-info) but didn't succed to import it [i use python 3.7.4 64-bit (conda) using VS-Code with Jupyter extention] here is my log:

UnicodeDecodeError Traceback (most recent call last)

in ----> 1 import dolo ~\Anaconda3\lib\site-packages\dolo\__init__.py in 1 from dolo.version import __version_info__, __version__ 2 ----> 3 import dolang 4 5 from dolo.config import * ~\Anaconda3\lib\site-packages\dolang\__init__.py in 2 from dolang.yaml_tools import yaml 3 ----> 4 from dolang.grammar import parse_string 5 from dolang.grammar import ( 6 stringify, ~\Anaconda3\lib\site-packages\dolang\grammar.py in 27 DATA_PATH = os.path.join(DIR_PATH, "grammar.lark") 28 ---> 29 grammar_0 = open(DATA_PATH, "rt").read() 30 31 ~\Anaconda3\lib\encodings\cp1252.py in decode(self, input, final) 21 class IncrementalDecoder(codecs.IncrementalDecoder): 22 def decode(self, input, final=False): ---> 23 return codecs.charmap_decode(input,self.errors,decoding_table)[0] 24 25 class StreamWriter(Codec,codecs.StreamWriter): UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1179: character maps to
TimMunday commented 3 years ago

I'm using windows, changing line 29 in grammar.py to:

grammar_0 = open(DATA_PATH, "rt", encoding='utf-8').read()

solves the problem as now the encoding is specified, otherwise it seems windows is confused.

Can submit a PR if needed

albop commented 3 years ago

Thank you! I thought this bug had been fixed, (and grammar.py moved to dolang.py : https://github.com/EconForge/dolang.py/blob/master/dolang/grammar.py) Maybe I need to do a new release.

On Thu, Jun 24, 2021 at 12:35 PM TimMunday @.***> wrote:

I'm using windows, changing line 29 in grammar.py to:

grammar_0 = open(DATA_PATH, "rt", encoding='utf-8').read()

solves the problem as now the encoding is specified, otherwise it seems windows is confused.

Can submit a PR if needed

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/EconForge/dolo.py/issues/223#issuecomment-867529380, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACDSKPGJJ5V3XW6TV65QMDTUMC65ANCNFSM4X3KHAEQ .