NeuralDialog-LAED icon indicating copy to clipboard operation
NeuralDialog-LAED copied to clipboard

code not working on python 3.5 TypeError: a bytes-like object is required, not 'str'

Open gwen10nnyson opened this issue 5 years ago • 3 comments

Traceback (most recent call last): File "ptb-utt.py", line 155, in main(config) File "ptb-utt.py", line 97, in main prepare_dirs_loggers(config, os.path.basename(file)) File "C:\Users\hw\NeuralDialog-LAED-master\laed\utils.py", line 105, in prepare_dirs_loggers json.dump(config.dict, fp, indent=4, sort_keys=True) File "C:\Users\hw\Anaconda3\envs\py35\lib\json_init_.py", line 179, in dump fp.write(chunk) TypeError: a bytes-like object is required, not 'str'

gwen10nnyson avatar Dec 01 '18 13:12 gwen10nnyson

The code is written in Python 2.7. Thanks!

snakeztc avatar Dec 03 '18 17:12 snakeztc

Yes, I understand. but is there any way it can work on python 3.5? because I am using windows and tensorflow is not supported on python 2.7

gwen10nnyson avatar Dec 03 '18 21:12 gwen10nnyson

For future reference, this model is largely compatible with python 3. You just have to change all of the calls to open(...,'wb') to open(...,'w'), as you are not writing bytes to the files. Alternatively, encode strings as bytes before writing them.

Also, as the MosesTokenizer is no longer included in nltk, you should separately install the sacremoses package, which is the same.

hannamw avatar Dec 11 '19 04:12 hannamw