locale.Error: unsupported locale settingThe solution of


0. Reference materials

Stackoverflow.com/questions/1…


1. Error causes are reported

Python3 -m venv venv: python3 -m venv: python3 -m venv

vagrant@ubuntu-xenial:~/microblog$ pip3 list Traceback (most recent call last): File "/usr/bin/pip3", line 11, in <module> sys.exit(main()) File "/usr/lib/python3/dist-packages/pip/__init__.py", Line 215, in the main locale. Setlocale (locale LC_ALL, ' ') File "/ usr/lib/python3.5 / locale py", line 594, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale settingCopy the code

The reason is that the system lacks the corresponding language package, which needs to be downloaded and installed.


2. Solutions

Use locale to view the current language Settings:

vagrant@ubuntu-xenial:~$ locale
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=zh_CN.UTF-8
LC_TIME=zh_CN.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=zh_CN.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=zh_CN.UTF-8
LC_NAME=zh_CN.UTF-8
LC_ADDRESS=zh_CN.UTF-8
LC_TELEPHONE=zh_CN.UTF-8
LC_MEASUREMENT=zh_CN.UTF-8
LC_IDENTIFICATION=zh_CN.UTF-8
LC_ALL=
Copy the code

Two languages are found in this setting, en_US.utF-8 and zh_cn.utF-8.

Run the locale-a command to view all available languages in the system:

vagrant@ubuntu-xenial:~$ locale -a
C
C.UTF-8
en_US.utf8
id_ID.utf8
POSIX
Copy the code

It was found that zh_cn.utF-8 was missing from the available language above, which is why the error was reported.

Sudo apt install language-pack-zh-hans

vagrant@ubuntu-xenial:~$ sudo apt install language-pack-zh-hans Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: language-pack-zh-hans-base The following NEW packages will be installed: language-pack-zh-hans language-pack-zh-hans-base 0 upgraded, 2 newly installed, 0 to remove and 3 not upgraded. Need to get 2110 kB of archives. After this operation, 8545 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Get: 1 http://archive.ubuntu.com/ubuntu xenial updates/main amd64 language pack - useful - Hans - base all 1:16. 04 + 20160627 [2108 kB] Get: 2 http://archive.ubuntu.com/ubuntu xenial updates/main amd64 language pack - useful - Hans all 1:16. 04 + 20160627 [1870 B] Fetched 2110 kB in 3s (567 kB/s) perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LC_TIME = "zh_CN.UTF-8", LC_MONETARY = "zh_CN.UTF-8", LC_ADDRESS = "zh_CN.UTF-8", LC_TELEPHONE = "zh_CN.UTF-8", LC_NAME = "zh_CN.UTF-8", LC_MEASUREMENT = "zh_CN.UTF-8", LC_IDENTIFICATION = "zh_CN.UTF-8", LC_NUMERIC = "zh_CN.UTF-8", LC_PAPER = "zh_CN.UTF-8", LANG = "en_US.UTF-8" are supported and installed on your system. perl: warning: Falling back to a fallback locale ("en_US.UTF-8"). locale: Cannot set LC_ALL to default locale: No such file or directory Selecting previously unselected package language-pack-zh-hans-base. (Reading database ... 89747 files and directories currently installed.) Preparing to unpack ... / language - pack - useful - Hans - base_1%3 a16. 04 + 20160627 _all. Deb... Unpacking language pack - useful - Hans - base (1:16. 04 + 20160627)... Selecting previously unselected package language-pack-zh-hans. Preparing to unpack ... / language - pack - useful - hans_1%3 a16. 04 + 20160627 _all. Deb... Unpacking language - pack - useful - Hans (1:16. 04 + 20160627)... Setting up language-pack-zh-Hans (1:16.04+20160627)... Setting up language-pack-zh-hans-base (1:16.04+20160627)... Generating locales (this might take a while)... zh_CN.UTF-8... done zh_SG.UTF-8... done Generation complete.Copy the code

Finally, we generate the zh_CN.utF-8 language we need.

Pip3 list and python3 -m venv venv will not return an error.