$ python --version
Python 2.7.5+
UnicodeEncodeErrorが発生した場合は、sitecustomize.pyでデフォルトのエンコーディングを指定する。 /usr/lib/python2.7/sitecustomize.pyInstaller
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
ii python3-pip 1.5.6-5ubuntu2 all alternative Python package installer - Python 3 version of the package
Python3 をデフォルトにする
Arch Linuxsudo apt install python-is-python3
# pacman -S python-pip # pip install pymssql
モジュールのバージョンを調べる$ python3 Python 3.4.3 (default, Mar 26 2015, 22:03:40) [GCC 4.9.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pymssql >>> type (pymssql) <class 'module'> >>> print (pymssql.__file__) /home/uchida/.local/lib/python3.4/site-packages/pymssql.cpython-34m.so >>> quit ()
Ubuntu$ python Python 3.6.2 (default, Jul 20 2017, 03:52:27) [GCC 7.1.1 20170630] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import requests >>> requests.__version__ '2.18.3' >>> quit()
$ python3 Python 3.4.3+ (default, Oct 14 2015, 16:03:50) [GCC 5.2.1 20151010] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> print (sys.path) ['', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu', '/usr/lib/python3.4/lib-dynload', '/usr/local/lib/python3.4/dist-packages', '/usr/lib/python3/dist-packages'] >>>エラー UnicodeEncodeError: 'ascii' codec can't encode characters in position 23-33: ordinal not in range(128)
json_str.encode('utf-8')