8000 decode the execution path string based file system encoding · matplotlib/matplotlib@4cb27c0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4cb27c0

Browse files
author
sohero
committed
decode the execution path string based file system encoding
When my py file importing matplotlib run in a folder where the path contains gbk encoding character, matplotlib will raise a unicode decode error.The changes in line 666/673/679 will fix the problem.
1 parent 27a648a commit 4cb27c0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/matplotlib/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,20 +663,20 @@ def _get_data_path():
663663
'directory')
664664
return path
665665

666-
path = os.sep.join([os.path.dirname(__file__), 'mpl-data'])
666+
path = os.sep.join([os.path.dirname(__file__.decode(sys.getfilesystemencoding())), 'mpl-data'])
667667
if os.path.isdir(path):
668668
return path
669669

670670
# setuptools' namespace_packages may highjack this init file
671671
# so need to try something known to be in matplotlib, not basemap
672672
import matplotlib.afm
673-
path = os.sep.join([os.path.dirname(matplotlib.afm.__file__), 'mpl-data'])
673+
path = os.sep.join([os.path.dirname(matplotlib.afm.__file__.decode(sys.getfilesystemencoding())), 'mpl-data'])
674674
if os.path.isdir(path):
675675
return path
676676

677677
# py2exe zips pure python, so still need special check
678678
if getattr(sys, 'frozen', None):
679-
exe_path = os.path.dirname(sys.executable)
679+
exe_path = os.path.dirname(sys.executable.decode(sys.getfilesystemencoding()))
680680
path = os.path.join(exe_path, 'mpl-data')
681681
if os.path.isdir(path):
682682
return path

0 commit comments

Comments
 (0)
0