Change python default encoding to utf-8

I get this error

#What to do if you get an error like this
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position xx: ordinal not in range(128)

Determine the cause of the error

import sys
print sys.getdefaultencoding()
#>>'ascii'This is utf because ascii is the default-The goal is to be 8

Find the location (site-packages directory) where the configuration files should be placed

#site-Find a folder called pacages
find / -name site-packages

#I think there are some results, but if you are using homebrew python, this is awkward
#/usr/local/lib/python2.7/site-packages/

Add the following to the top of the config file

Add the following to the top of sitecustomize.py in the site-packages identified above

sitecustomize.py


import sys
sys.setdefaultencoding("utf-8")

Make sure the problem is resolved

import sys
sys.getdefaultencoding()
#>>'utf-8'The default encoding is utf-Became 8

Recommended Posts

Change python default encoding to utf-8
To set default encoding to utf-8 in python
[Python] Convert Shift_JIS to UTF-8
How to change Python version
Python encoding
[Raspberry Pi] Changed Python default to Python3
[Python] Change the alphabet to numbers
Did not change from Python 2 to 3
Change Python 64bit environment to 32bit environment with Anaconda
Updated to Python 2.7.9
"Backport" to python 2
[Python] How to change the date format (display format)
How to install Python
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
python> Change file owner> os.chown ("path / to / file", uid, gid)
Change IP settings to ACL of conoha with python
Rewrite Python2 code to Python3 (2to3)
Python default argument behavior
How to install python
python decorator to retry
Introduction to Python language
Introduction to OpenCV (python)-(2)
[Python] Change standard input from keyboard to text file
Note to daemonize python
How to change static directory from default in Flask
Introducing Python 2.7 to CentOS 6.6
Encoding judgment in Python
[Work efficiency] How to change file names in Python
Connect python to mysql
[Python MinMaxScaler] Normalize to 0 ~ 1
Change Maya Python Timeline
[python] Change the image file name to a serial number
[Introduction to Udemy Python3 + Application] 50. Positional arguments, keyword arguments, and default arguments
Web application with Python3.3.1 + Bottle (1) --Change template engine to jinja2
[Python] How to change EXCEL file saved in xlsb to xlsx
[Introduction to Udemy Python3 + Application] 51. Be careful with default arguments
Connect to BigQuery with Python
[2020.8 latest] How to install Python
UTF8 text processing in python
[python] Convert date to string
Post from Python to Slack
How to install Python [Windows]
Post to vim → Python → Slack
Base64 encoding images in Python 3
Introduction to Python Django (2) Win
To flush stdout in Python
Convert numpy int64 to python int
python3: How to use bottle (2)
[Python] Convert list to Pandas [Pandas]
Cheating from PHP to Python
Try to understand Python self
Python notes to forget soon
[Python] How to use list 1
How to change Jupyter layout
Login to website in Python
How to update Python Tkinter to 8.6
Post to slack with Python 3
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Website change monitoring using python
Post to Twitter using Python