Skip to content

nipype raising UnicodeEncodeError; fixed when writing files with encoding='utf-8' #2942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
binarybottle opened this issue Jun 10, 2019 · 1 comment · Fixed by #3508
Closed

Comments

@binarybottle
Copy link
Member

binarybottle commented Jun 10, 2019

Summary

When running nipy/mindboggle, nipype raises a UnicodeEncodeError in multiple places where files are written. This is fixed when adding "encoding='utf-8'".

Actual behavior

Here are three instances in two files:

File "/opt/miniconda-latest/envs/mb/lib/python3.6/site-packages/nipype/utils/filemanip.py", line 694, in crash2txt
fp.write('Node inputs:\n{}\n'.format(node.inputs))
UnicodeEncodeError: 'ascii' codec can't encode character '\u2019' in position 495764: ordinal not in range(128)

File "/opt/miniconda-latest/envs/mb/lib/python3.6/site-packages/nipype/pipeline/engine/utils.py", li
ne 225, in write_report

File "/opt/miniconda-latest/envs/mb/lib/python3.6/site-packages/nipype/pipeline/engine/utils.py", line 141, in write_report
fp.write('\n'.join(lines))
UnicodeEncodeError: 'ascii' codec can't encode character '\u2019' in position 1765: ordinal not in range(128)

Expected behavior

How to replicate the behavior

Script/Workflow details

Please put URL to code or code here (if not too long).

Platform details:

neurodocker.sh:
--miniconda
conda_install="python=3.6 pip jupyter cmake mesalib vtk=8.2 pandas
matplotlib colormath nipype>=1.1.4 tbb-devel nose" \

nipype 1.2.0-py36_0

{'commit_hash': '%h',
 'commit_source': 'archive substitution',
 'networkx_version': '2.3',
 'nibabel_version': '2.4.1',
 'nipype_version': '1.2.0',
 'numpy_version': '1.16.4',
 'pkg_path': '/opt/miniconda-latest/envs/mb/lib/python3.6/site-packages/nipype',
 'scipy_version': '1.3.0',
 'sys_executable': '/opt/miniconda-latest/envs/mb/bin/python',
 'sys_platform': 'linux',
 'sys_version': '3.6.7 | packaged by conda-forge | (default, Feb 28 2019, '
                '09:07:38) \n'
                '[GCC 7.3.0]',
 'traits_version': '5.1.1'}

Execution environment

Choose one

  • Container [Tag: nipy/mindboggle]
  • My python environment inside container [Base Tag: ???]
    Python 3.6.7 | packaged by conda-forge | (default, Feb 28 2019, 09:07:38)
  • My python environment outside container
@binarybottle
Copy link
Member Author

binarybottle commented Jun 11, 2019

Within the docker container, UTF-8 is set by default:

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

I also setting:

ENV PYTHONIOENCODING=utf-8

and ran (https://stackoverflow.com/questions/43356982/docker-python-set-utf-8-locale):

docker run -e PYTHONIOENCODING=UTF-8 ...

all to no avail.

The only thing that seems to work is to set "encoding='utf-8'" in the python functions, as mentioned above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant