band-unfolding / bandup

BandUP: Band Unfolding code for Plane-wave based calculations
http://www.ifm.liu.se/theomod/compphys/band-unfolding
GNU General Public License v3.0
99 stars 49 forks source link

Fix python3.6 #21

Closed nhew1994 closed 3 years ago

nhew1994 commented 3 years ago

@stepan-tsirkin @fraricci

The files.py, runners.py, and warnings_wrapper.py are exactly the same from #7 . Changes were made to orbital_contributions.py, unfolding_density_op.py, and vasp.py to make it compatible with python3.6. It works alright for me. Hope this helps.

Regards, Nigel Hew

stepan-tsirkin commented 3 years ago

thank you @nhew1994 , @fraricci

I also added encoding on line 52 of runners.py , but still on step 4 I was getting an error when using python 3.6 on my cluster :

Traceback (most recent call last):
  File "/disk/data11/tfp/stepan/bandup/bandup", line 73, in <module>
    run_requested_task(args)
  File "/disk/data11/tfp/stepan/bandup/src/python_interface/bandupy/runners.py", line 63, in run_requested_task
    run_bandup(args)
  File "/disk/data11/tfp/stepan/bandup/src/python_interface/bandupy/runners.py", line 39, in run_bandup
    sys.stdout.write(line)
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2502' in position 6: ordinal not in range(256)

while it was fine on python3.8 on my Ubuntu 20.04 desktop. I think it is not a problem of python version, but rather with the default encoding of the shell. Switching to 'latin-1' solved the problem for me (for my both machines), but will it work in general. Could you double check, if it works for you, or if you know a better, more universal solution?

nhew1994 commented 3 years ago

Hello @stepan-tsirkin, yes I had the same error. I used "export LANG=en_US.UTF-8" and "export LC_ALL=en_US.UTF-8" to get it working on the machine I am using. At the moment I don't know a better solution than that.

fraricci commented 3 years ago

about the encoding, I know it is possible to change it internally in python with the "locale" package (some examples here https://phrase.com/blog/posts/beginners-guide-to-locale-in-python/). It might be an option.