Unicode Python decoding error when importing matplotlib

I am trying to use matplotlib in my python script, but I got this error in terminal:

Traceback (most recent call last):
  File "graphique.py", line 5, in <module>
    import matplotlib.pyplot as plt
  File "/home/xavier/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py", line 1048, in <module>
    rcParams = rc_params()
  File "/home/xavier/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py", line 897, in rc_params
    fname = matplotlib_fname()
  File "/home/xavier/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py", line 748, in matplotlib_fname
    fname = os.path.join(os.getcwd(), 'matplotlibrc')
  File "/home/xavier/anaconda/lib/python2.7/posixpath.py", line 80, in join
    path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 66: ordinal not in range(128)

Here is my python code, I just wrote

# -*- coding: utf-8 -*-
import numpy as np
from math import *
import matplotlib.pyplot as plt

What should I do?

+1
source share
1 answer

The problem is that you have a non-ASCII character in the current working directory.

This actually should not be a problem at all, but this is due to a combination of other things:

  • matplotlibwants to look in your current working directory for a local file matplotlibrcthat overrides your default.
  • Python believes that you are using the C locale instead of the pretty UTF-8 locale that Ubuntu 14 should run by default.

, script , -ASCII-.

:

  • , Ubuntu 14, Anaconda matplotlib.
  • echo $LANG. , - UTF-8 . , AskUbuntu, .
  • , UTF-8.

matplotlib # 3516, # 3594, , , matplotlib 1.4.1+. . # 3487. , , $LANG , matplotlib - 1.4.0 , ( conda pip apt-get) Anaconda , ) .

, , Python 3, , , , , , . (, , , matplotlib 1.4.0 Python 3, Python 2, ... ...)

+2

Source: https://habr.com/ru/post/1615434/


All Articles