Open Source Development

Power Open Source Development

Explore the open source tools and capabilities for building and deploying modern applications on IBM Power platforms including AIX, IBM i, and Linux.


#Power


#Power

 View Only
  • 1.  python3.9: unsupported locale setting

    Posted Tue September 05, 2023 12:27 PM

    If I try to set locale in python3.9 from AIX toolbox, I get the error 'unsupported locale setting':

    #python3.9
    Python 3.9.17 (main, Jul  5 2023, 06:17:22) 
    [GCC 10.3.0] on aix
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import locale
    >>> locale.setlocale(locale.LC_ALL, '')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/opt/freeware/lib64/python3.9/locale.py", line 610, in setlocale
        return _setlocale(category, locale)
    locale.Error: unsupported locale setting
    

    If I do the same with AIX standard python3.9 everything is OK:

    #python3
    Python 3.9.12 (main, Apr 19 2022, 06:10:02) 
    [IBM XL C/C++ for AIX 13.1.3.7] on aix
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import locale
    >>> locale.setlocale(locale.LC_ALL, '')
    'en_US.UTF-8 en_US.UTF-8 en_US.UTF-8 en_US.UTF-8 en_US.UTF-8 en_US.UTF-8'
    >>> dummy, encoding=locale.getlocale()
    >>> dummy
    'en_US'
    >>> encoding
    'UTF-8'
    >>> 
    

    The locale is installed and everything looks fine for me:

    #echo $LANG
    en_US.UTF-8
    #locale -a
    C
    POSIX
    EN_US.UTF-8
    EN_US
    en_US.8859-15
    en_US.IBM-858
    en_US.ISO8859-1
    en_US.UTF-8
    en_US
    

    I have the problem on this one server. All other work without problems. What could be the cause of the problem?



    ------------------------------
    Andrey Klyachkin

    https://www.power-devops.com
    ------------------------------

    #AIXOpenSource


  • 2.  RE: python3.9: unsupported locale setting

    Posted Tue September 05, 2023 01:48 PM

    Tried setlocale() with gcc and it works without problems on the server.

    #include <stdio.h>
    #include <locale.h>
    
    void main() {
      char *rc;
      rc = setlocale(LC_ALL, "");
      if (!rc) {
        fprintf(stderr, "setlocale() returned NULL\n");
        return;
      }
      printf("result is %s\n", rc);
    }
    

    Output:

    #gcc -o locale locale.c
    #./locale
    result is en_US.UTF-8 en_US.UTF-8 en_US.UTF-8 en_US.UTF-8 en_US.UTF-8 en_US.UTF-8
    


    ------------------------------
    Andrey Klyachkin

    https://www.power-devops.com
    ------------------------------



  • 3.  RE: python3.9: unsupported locale setting

    Posted Tue December 19, 2023 06:25 AM

    Did one more test on the system with the problem.

    32-bit python (/opt/freeware/libexec/python3.9_32) works without problems:

    # /opt/freeware/libexec/python3.9_32
    Python 3.9.18 (main, Sep 19 2023, 04:59:07) 
    [GCC 10.3.0] on aix
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import locale
    >>> locale.setlocale(locale.LC_ALL)
    'C EN_US C C C C'
    >>> locale.setlocale(locale.LC_ALL, '')
    'EN_US EN_US EN_US EN_US EN_US EN_US'
    >>> 
    

    The problem is only with 64-bit Python.

    btw I am not the only one with the problem. I was contacted from several customers if I found a solution to the problem.



    ------------------------------
    Andrey Klyachkin

    https://www.power-devops.com
    ------------------------------



  • 4.  RE: python3.9: unsupported locale setting

    Posted Tue December 19, 2023 07:10 AM

    Hi Andrey, 
    Thanks for reporting it. We will check it out and update.



    ------------------------------
    Ayappan P
    ------------------------------



  • 5.  RE: python3.9: unsupported locale setting

    Posted Tue December 19, 2023 07:46 AM

    It looks like I ocasionally found the cause of the problem.

    shr4_64.o was missing in /opt/freeware/lib/libiconv.a. After I added it into libiconv.a, I don't get 'unsupported locale setting' anymore:

    #/opt/freeware/bin/python3.9
    Python 3.9.18 (main, Sep 19 2023, 04:57:07) 
    [GCC 10.3.0] on aix
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import locale
    >>> locale.setlocale(locale.LC_ALL, '')
    'EN_US EN_US EN_US EN_US EN_US EN_US'
    


    ------------------------------
    Andrey Klyachkin

    https://www.power-devops.com
    ------------------------------



  • 6.  RE: python3.9: unsupported locale setting

    Posted Tue December 19, 2023 08:02 AM

    Okay. libiconv rpm has post install script which actually takes the shared objects from /usr/lib/libiconv.a and add it to /opt/freeware/lib/libiconv.a.
    Not sure whether any scenario exists where this script fails to add shr4_64.o to /opt/freeware/lib/libiconv.a archive.

    # rpm -q --scripts libiconv
    postinstall scriptlet (using /bin/sh):
    # we need to include all shared members of the system wide /usr/lib/libiconv.a
    # at rpm installation time to avoid core dump of system binaries

    export AR="/usr/bin/ar -X32_64"

    /usr/bin/mkdir -p /tmp/libiconv.tmp
    cd  /tmp/libiconv.tmp
    /usr/sbin/slibclean
    LIST=`${AR} -t /usr/lib/libiconv.a`
    ${AR} -x /usr/lib/libiconv.a
    /usr/bin/strip -X32_64 -e *
    /usr/bin/cp -f /opt/freeware/lib/libiconv.a .
    for i in ${LIST}
    do
       if [ "$i" != "libiconv.so.2" ]; then
         echo "add $i shared members from /usr/lib/libiconv.a to  /opt/freeware/lib/libiconv.a"
        ${AR} -r libiconv.a ${i}
       fi
    done
    /usr/bin/cp -f libiconv.a /opt/freeware/lib/libiconv.a
    cd -
    /usr/bin/rm -rf /tmp/libiconv.tmp



    ------------------------------
    Ayappan P
    ------------------------------



  • 7.  RE: python3.9: unsupported locale setting

    Posted Tue December 19, 2023 08:20 AM

    yes, it has and I have the latest installed libiconv on the system. I repeated the steps from the post-install script after I've found out that shr4_64.o is missing. 

    I don't know either what could lead to the problem but because I saw enough messages about libiconv problems here in the forum and IRL, I think there should be a better solution...



    ------------------------------
    Andrey Klyachkin

    https://www.power-devops.com
    ------------------------------