nipy / mindboggle

Automated anatomical brain label/shape analysis software (+ website)
http://mindboggle.info
Other
143 stars 54 forks source link

UnicodeEncodeError: 'ascii' codec can't encode character '\u2019' #175

Closed binarybottle closed 5 years ago

binarybottle commented 5 years ago

Running:

mindboggle $FREESURFER_SUBJECT --out $OUT --no_volumes --no_moments --no_spectra --no_sulci

results in UnicodeEncodeError in multiple places within nipype:

Traceback (most recent call last): File "/opt/miniconda-latest/envs/mb/lib/python3.6/site-packages/nipype/pipeline/plugins/linear.py", line 48, in run node.run(updatehash=updatehash) File "/opt/miniconda-latest/envs/mb/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 487, in run self, report_type='postexec', is_mapnode=isinstance(self, MapNode)) File "/opt/miniconda-latest/envs/mb/lib/python3.6/site-packages/nipype/pipeline/engine/utils.py", line 225, in write_report fp.write('\n'.join(lines)) UnicodeEncodeError: 'ascii' codec can't encode character '\u2019' in position 1641: ordinal not in range(128)

This is despite the fact that within the docker container, UTF-8 is set by default:

root@374580a45eb2:/opt# locale -a C C.UTF-8 en_US.utf8 POSIX

and seems resistant to setting ENV PYTHONIOENCODING=utf-8

or running (https://stackoverflow.com/questions/43356982/docker-python-set-utf-8-locale): docker run -e PYTHONIOENCODING=UTF-8 ...

The only thing that seems to work is to set "encoding='utf-8'" in the nipype python functions themselves.

I have left an issue in the nipy/nipype repo: https://github.com/nipy/nipype/issues/2942

binarybottle commented 5 years ago

I added "encoding='utf-8'" to write commands (all open file handle commands, except pickle writes) in two nipype files within mindboggle's docker image that generate reports for mindboggle:

Example (line 688 of filemanip.py):

with open(filename, 'w') as fp: to with open(filename, 'w', encoding='utf-8') as fp:

Mindboggle runs fine now, so I will update the docker image (docker commit, as in https://docs.docker.com/engine/reference/commandline/commit/), push the image to docker hub, and wait for a fix at nipype's end for future releases.