[PYTHON] Let's use usercustomize.py instead of sitecustomize.py

Why not put ʻusercustomize.py before puttingsitecustomize.py`?

Location

python


>>> import site
>>> userdir = site.getusersitepackages()

entity

windows


>>> userdir()
'C:\\Users\\owner\\AppData\\Roaming\\Python\\Python27\\site-packages'

ubuntu


>>> userdir()
'/home/owner/.local/lib/python2.7/site-packages'

mac


>>> userdir()
'/Users/owner/Library/Python/2.7/lib/python/site-packages'

Create a directory

windows


>>> os.makedirs(userdir)
>>> os.system('explorer.exe %s' % userdir)
1

Create usercustomize.py

windows


>>> f = open("%s\\usercustomize.py" % userdir,"w")
>>> str="""import sys
... sys.setdefaultencoding('utf-8')
... """
>>> f.write(str)
>>> f.close()

Check if the processing of usercustomize.py is applied

python


>>> import sys
>>> sys.getdefaultencoding()
'utf-8'

If it fails, ʻascii` is displayed.

Recommended Posts

Let's use usercustomize.py instead of sitecustomize.py
Let's use tomotopy instead of gensim
R: Use Japanese instead of Japanese in scripts
Let's use pytube
Let's use different versions of SQLite3 from Python3!
Convenient use of ipython
Let's use the API of the official statistics counter (e-Stat)
Use urlparse.urljoin instead of os.path.join for Python URL joins
Graceful use of MySQLdb
Let's use the Python version of the Confluence API module.
Let's use the open data of "Mamebus" in Python
EP 7 Use List Comprehensions Instead of map and filter
Let's use the distributed expression of words quickly with fastText!
Let's use python janome easily
Let's use python's wordcloud easily!
Let's visualize GraphConvModel of DeepChem
Let's use MemSQL Vol.14: Practice 7
Use and integration of "Shodan"
Let's use MemSQL Vol.13: Practice 6
It is convenient to use Icecream instead of print when debugging.