0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【virtualenv】python3.5の仮想環境構築の際のunsupported locale setting エラー

Last updated at Posted at 2018-07-20

目的

python3.5のvirtualenv環境を作成する.

詰まったところ

username@machinename:~$ which python3.5
/usr/bin/python3.5
username@machinename:~$ virtualenv -p /usr/bin/python3.5 py3.5
Running virtualenv with interpreter /usr/bin/python3.5
Using base prefix '/usr'
New python executable in /home/username/py3.5/bin/python3.5
Also creating executable in /home/username/py3.5/bin/python
Installing setuptools, pkg_resources, pip, wheel...
  Complete output from command /home/username/py3.5/bin/python3.5 - setuptools pkg_resources pip wheel:
  Traceback (most recent call last):
  File "<stdin>", line 24, in <module>
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/__init__.py", line 215, in main
  File "/home/username/py3.5/lib/python3.5/locale.py", line 594, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting
----------------------------------------
...Installing setuptools, pkg_resources, pip, wheel...done.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 2363, in <module>
    main()
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 719, in main
    symlink=options.symlink)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 988, in create_environment
    download=download,
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 918, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 812, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /home/username/py3.5/bin/python3.5 - setuptools pkg_resources pip wheel failed with error code 1
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
ImportError: No module named 'apport'

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 2363, in <module>
    main()
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 719, in main
    symlink=options.symlink)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 988, in create_environment
    download=download,
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 918, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 812, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /home/username/py3.5/bin/python3.5 - setuptools pkg_resources pip wheel failed with error code 1

最初はOSErrorで,深刻な問題かと思ったが, 実はエラーの中盤にある

locale.Error: unsupported locale setting

のlocaleに関するエラーだと判明した.
※localeとは
https://eng-entrance.com/linux-localization-locale

なんだか,サーバー(マシン)毎に設定されている,文字コードや地域等の初期設定に関するものらしい.
項目としてはいろいろあって,

username@machinename:~$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: LC_ALL??????????????????: ??????????????????????
LANG=ja_JP.UTF-8
LANGUAGE=
LC_CTYPE=UTF-8
LC_NUMERIC="ja_JP.UTF-8"
LC_TIME="ja_JP.UTF-8"
LC_COLLATE="ja_JP.UTF-8"
LC_MONETARY="ja_JP.UTF-8"
LC_MESSAGES="ja_JP.UTF-8"
LC_PAPER="ja_JP.UTF-8"
LC_NAME="ja_JP.UTF-8"
LC_ADDRESS="ja_JP.UTF-8"
LC_TELEPHONE="ja_JP.UTF-8"
LC_MEASUREMENT="ja_JP.UTF-8"
LC_IDENTIFICATION="ja_JP.UTF-8"
LC_ALL=

使い始めのマシンの状態だと,設定されている項目,まだ設定されていない項目が混じっている模様.

解決方法

今回は,この

LC_ALL=

がまだ指定されていなかったので,コマンド上で他の項目と同様に日本語のUTF-8として,指定することにする.

username@machinename:~$ export LC_ALL="ja_JP.UTF-8"

すると,

username@machinename:~$ virtualenv -p /usr/bin/python3.5 py3.5
Running virtualenv with interpreter /usr/bin/python3.5
Using base prefix '/usr'
New python executable in /home/username/py3.5/bin/python3.5
Not overwriting existing python script /home/username/py3.5/bin/python (you must use /home/username/py3.5/bin/python3.5)
Installing setuptools, pkg_resources, pip, wheel...done.

となって,virtualenv環境が作成できた模様.

username@machinename:~$ source py3.5/bin/activate
(py3.5) username@machinename:~$

ちゃんとvirtualenv環境内にも入れました.

(一応, .bashrcにも追加しておく.)
emacs .bashrc

以下の行をファイルの一番下に追加する.

export LC_ALL="ja_JP.UTF-8"

これで,次回のログインからも,LC_ALL="ja_JP.UTF-8"が指定された状態になっているであろう.

−参考
http://nekoyukimmm.hatenablog.com/entry/2016/04/05/093316

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?