pip install - locale.Error: unsupported locale setting

后端 未结 9 1156
时光取名叫无心
时光取名叫无心 2020-12-07 06:58

Full stacktrace:

➜  ~ pip install virtualenv
Traceback (most recent call last):
  File \"/usr/bin/pip\", line 11, in 
    sys.exit(main())
           


        
9条回答
  •  广开言路
    2020-12-07 07:10

    [This answer is target on linux platform only]

    The first thing you should know is most of the locale config file located path can be get from localedef --help :

    $ localedef --help | tail -n 5
    System's directory for character maps : /usr/share/i18n/charmaps
                           repertoire maps: /usr/share/i18n/repertoiremaps
                           locale path    : /usr/lib/locale:/usr/share/i18n
    For bug reporting instructions, please see:
    
    

    See the last /usr/share/i18n ? This is where your xx_XX.UTF-8 config file located:

    $ ls /usr/share/i18n/locales/zh_*
    /usr/share/i18n/locales/zh_CN  /usr/share/i18n/locales/zh_HK  /usr/share/i18n/locales/zh_SG  /usr/share/i18n/locales/zh_TW
    

    Now what ? We need to compile them into archive binary. One of the way, e.g. assume I have /usr/share/i18n/locales/en_LOVE, I can add it into compile list, i.e. /etc/locale-gen file:

    $ tail -1 /etc/locale.gen 
    en_LOVE.UTF-8 UTF-8
    

    And compile it to binary with sudo locale-gen:

    $ sudo locale-gen 
    Generating locales (this might take a while)...
      en_AG.UTF-8... done
      en_AU.UTF-8... done
      en_BW.UTF-8... done
      ...
      en_LOVE.UTF-8... done
    Generation complete.
    

    And now update the system default locale with desired LANG, LC_ALL ...etc with this update-locale:

    sudo update-locale LANG=en_LOVE.UTF-8
    

    update-locale actually also means to update this /etc/default/locale file which will source by system on login to setup environment variables:

    $ head /etc/default/locale 
    #  File generated by update-locale
    LANG=en_LOVE.UTF-8
    LC_NUMERIC="en_US.UTF-8"
    ...
    

    But we may not want to reboot to take effect, so we can just source it to environment variable in current shell session:

    $ . /etc/default/locale
    

    How about sudo dpkg-reconfigure locales ? If you play around it you will know this command basically act as GUI to simplify the above steps, i.e. Edit /etc/locale.gen -> sudo locale-gen -> sudo update-locale LANG=en_LOVE.UTF-8

    For python, as long as /etc/locale.gen contains that locale candidate and locale.gen get compiled, setlocale(category, locale) should work without throws locale.Error: unsupoorted locale setting. You can check the correct string en_US.UTF-8/en_US/....etc to be set in setlocale(), by observing /etc/locale.gen file, and then uncomment and compile it as desired. zh_CN GB2312 without dot in that file means the correct string is zh_CN and zh_CN.GB2312.

提交回复
热议问题