Skip to content
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

UnicodeDecodeError seems still exist #3804

Closed
johnwei01 opened this issue Nov 16, 2014 · 9 comments
Closed

UnicodeDecodeError seems still exist #3804

johnwei01 opened this issue Nov 16, 2014 · 9 comments

Comments

@johnwei01
Copy link

When I run “import pylab”, it will report the UnicodeDecodeError. The matplotlib version is matplotlib-1.4.2.win32-py2.7.exe and my system is win7-x64.

---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
 in ()
----> 1 import pylab

C:\Python27\lib\site-packages\pylab.py in ()
----> 1 from matplotlib.pylab import *
      2 import matplotlib.pylab
      3 __doc__ = matplotlib.pylab.__doc__

C:\Python27\lib\site-packages\matplotlib\pylab.py in ()
    229 # make mpl.finance module available for backwards compatability, in case folks
    230 # using pylab interface depended on not having to import it
--> 231 import matplotlib.finance
    232 
    233 from matplotlib.dates import date2num, num2date,\

C:\Python27\lib\site-packages\matplotlib\finance.py in ()
     36 from matplotlib.dates import date2num
     37 from matplotlib.cbook import iterable, mkdirs
---> 38 from matplotlib.collections import LineCollection, PolyCollection
     39 from matplotlib.colors import colorConverter
     40 from matplotlib.lines import Line2D, TICKLEFT, TICKRIGHT

C:\Python27\lib\site-packages\matplotlib\collections.py in ()
     25 import matplotlib.artist as artist
     26 from matplotlib.artist import allow_rasterization
---> 27 import matplotlib.backend_bases as backend_bases
     28 import matplotlib.path as mpath
     29 from matplotlib import _path

C:\Python27\lib\site-packages\matplotlib\backend_bases.py in ()
     54 
     55 import matplotlib.tight_bbox as tight_bbox
---> 56 import matplotlib.textpath as textpath
     57 from matplotlib.path import Path
     58 from matplotlib.cbook import mplDeprecation

C:\Python27\lib\site-packages\matplotlib\textpath.py in ()
     17 from matplotlib.path import Path
     18 from matplotlib import rcParams
---> 19 import matplotlib.font_manager as font_manager
     20 from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
     21 from matplotlib.ft2font import LOAD_TARGET_LIGHT

C:\Python27\lib\site-packages\matplotlib\font_manager.py in ()
    147     if home is not None:
    148         # user fonts on OSX
--> 149         path = os.path.join(home, 'Library', 'Fonts')
    150         OSXFontDirectories.append(path)
    151         path = os.path.join(home, '.fonts')

C:\Python27\lib\ntpath.pyc in join(path, *paths)
     82         if result_path and result_path[-1] not in '\\/':
     83             result_path = result_path + '\\'
---> 84         result_path = result_path + p_path
     85     ## add separator between UNC and non-absolute path
     86     if (result_path and result_path[0] not in '\\/' and

UnicodeDecodeError: 'ascii' codec can't decode byte 0xa3 in position 2: ordinal not in range(128)
@johnwei01
Copy link
Author

when I run "import matplotlib.pyplot as plt", the error still re reported.

UnicodeDecodeError                        Traceback (most recent call last)
 in ()
----> 1 import matplotlib.pyplot as plt
C:\Python27\lib\site-packages\matplotlib\pyplot.py in ()
     25 
     26 import matplotlib
---> 27 import matplotlib.colorbar
     28 from matplotlib import style
     29 from matplotlib import _pylab_helpers, interactive
C:\Python27\lib\site-packages\matplotlib\colorbar.py in ()
     32 import matplotlib.artist as martist
     33 import matplotlib.cbook as cbook
---> 34 import matplotlib.collections as collections
     35 import matplotlib.colors as colors
     36 import matplotlib.contour as contour
C:\Python27\lib\site-packages\matplotlib\collections.py in ()
     25 import matplotlib.artist as artist
     26 from matplotlib.artist import allow_rasterization
---> 27 import matplotlib.backend_bases as backend_bases
     28 import matplotlib.path as mpath
     29 from matplotlib import _path
C:\Python27\lib\site-packages\matplotlib\backend_bases.py in ()
     54 
     55 import matplotlib.tight_bbox as tight_bbox
---> 56 import matplotlib.textpath as textpath
     57 from matplotlib.path import Path
     58 from matplotlib.cbook import mplDeprecation
C:\Python27\lib\site-packages\matplotlib\textpath.py in ()
     17 from matplotlib.path import Path
     18 from matplotlib import rcParams
---> 19 import matplotlib.font_manager as font_manager
     20 from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
     21 from matplotlib.ft2font import LOAD_TARGET_LIGHT
C:\Python27\lib\site-packages\matplotlib\font_manager.py in ()
    147     if home is not None:
    148         # user fonts on OSX
--> 149         path = os.path.join(home, 'Library', 'Fonts')
    150         OSXFontDirectories.append(path)
    151         path = os.path.join(home, '.fonts')
C:\Python27\lib\ntpath.pyc in join(path, *paths)
     82         if result_path and result_path[-1] not in '\\/':
     83             result_path = result_path + '\\'
---> 84         result_path = result_path + p_path
     85     ## add separator between UNC and non-absolute path
     86     if (result_path and result_path[0] not in '\\/' and
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa3 in position 2: ordinal not in range(128)

@johnwei01
Copy link
Author

the matplotlib version is 1.4.2.
20141116085022

@tacaswell
Copy link
Member

@johnwei01 I am confused, why is this closed if you are still getting the problem.

@johnwei01
Copy link
Author

I don't know why this happen. I also try to modify the ntpath.py file, but it doesn't work.

@johnwei01
Copy link
Author

@tacaswell Now I comment the lines 145-152 of the "font_manager.py" file, it can work well now.

@tacaswell tacaswell reopened this Nov 16, 2014
@tacaswell tacaswell added this to the v1.4.3 milestone Nov 16, 2014
@tacaswell
Copy link
Member

What is the value of

home = os.environ.get('HOME')

Did this work on previous versions of mpl?

Do you have non-ascii characters in your user name?

@johnwei01
Copy link
Author

The home value is .;%USERPROFILE%.
Sorry that I haven't used matplotlib before.
My user namename is as below:
image

20141117071739

20141117092700

@tacaswell
Copy link
Member

It looks like the windows username is not getting expanded right.

I have very little experience with windows, @jbmohler @cgohlke can you take a look at this? Is the issue we are not expanding things or the configuration on the OP's system is not right?

@johnwei01 We are discouraging the use of from pylab import * in favor of

import matplotlib.pyplot as plt
import numpy as np

which does not pollute the namespace / silently clobber built in functions.

@jbmohler
Copy link
Contributor

A fresh windows install does not have a HOME environment variable, so this is something local to the OP's system (it does look like a clever (?) attempt at redirection to the analog of HOME on windows). It seems like this block of code in font_manager.py is irrelevant to windows and os.environ's semantics of returning None for unknown environment variables does that more-or-less by accident.

My reading would be that this isn't really a bug, but it would make it explicitly correct to augment the conditional

if not USE_FONTCONFIG:

with a " and sys.platform != 'win32'".

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Nov 21, 2014
This variable should not be defined on windows so don't
even bother looking at it.

addresses matplotlib#3804
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Nov 21, 2014
This variable should not be defined on windows so don't
even bother looking at it.

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

No branches or pull requests

3 participants