Troubleshooting

This chapter describes some common issues that you might encounter while creating your IBM® Open Enterprise SDK for Python applications.

For more troubleshooting information about multiprocessing considerations, see Multiprocessing considerations.

For more troubleshooting information about tagging files, see Tagging files.

Files extracted from ZIP archives have lost their sticky bit (S_ISVTX)

Due to compatibility and security reasons, ZIP member files will have the sticky bit turned off when extracted from their parent archive. You can manually set the sticky bit afterward to turn them on. Notice that the sticky bit for directories will not be affected.

IBM z/OS XL C/C++ failures

When using pip to install packages, they might require a C/C++ compiler. See Using IBM C/C++ compilers with IBM Open Enterprise SDK for Python 3.11 for more information on setting up a C/C++ compiler.

You can test your compiler by creating a new file with the following c program:

#include <stdio.h>

int main()
{
    printf("Hello, world!\n");
    return 0;
}
and run /bin/xlc <filename.c> to compile the file, and use ./a.out to run it.

If successful, the program will print out Hello, world! which means your compiler is ready to use with IBM Open Enterprise SDK for Python.

If you encounter the following error:
EDC5129I No such file or directory. (errno2=0x05940252) FSUM3221 xlc: Cannot spawn program /usr/lpp/cbclib/xlc/exe/ccndrvr - error: command '/bin/xlc' failed with exit code 255
it means that your z/OS® system is missing datasets which are created during the IBM z/OS XL C/C++ install process, and you should confirm if it has been installed successfully. For information about installation, check Using IBM C/C++ compilers with IBM Open Enterprise SDK for Python 3.11.
When importing a package, if you encounter an error similar to:
Import Error: CEE3512S An HFS load of module <path to filename.so> failed. The system return code is 0000000130 and the reason code is 0BDF0C27.
Then the package may have been tagged incorrectly when using IBM z/OS XL C/C++. Verify if the shared library is untagged by running:
ls -alT <path to filename.so>
If the file is tagged, with the following output message:
t ISO8859-1 T=on
you can remove the tag with the following command:
chtag -r <filename.so>

Fatal Python Error: Failed to get random numbers

Fatal Python error: _Py_HashRandomization_Init: failed to get random numbers to initialize Python

The above error shows up when you try to run Python without enabling Integrated Cryptographic Services Facility (ICSF). ICSF is typically responsible for supplying random data for /dev/urandom. You can run the following command to verify whether ICSF is enabled or not on your system.

head -c10 /dev/urandom

If ICSF is enabled, you will see random data and if it is not enabled on your system, you will encounter Internal Error.

For more information including installation guide, please refer to ICSF System Programmer's Guide and ICSF Administrator's Guide.

Python execution failure due to semaphore exhaustion

When semaphore exhaustion occurs on a machine, it can cause Python programs to fail in various ways. One common example will be an error message as follows:

_multiprocessing.SemLock(PermissionError: [Errno 139] EDC5139I Operation not permitted.

To diagnose whether semaphore exhaustion is an issue, you can run the following command to examine the number of semaphores that your user is currently using.

ipcs | grep <your ID>

If you run ipcs -y, you can get the limits for semaphores or the shared memory. If the number reported is close to that number, then it's likely that you are hitting the limit when running Python.

The following example shows how to approach cleaning up semaphore usage under your user id:

ipcs | grep <your ID> | awk '{print $2}' > semaphores_example.txt
for i in $(cat semaphores_example.txt) ; do { ipcrm -s $i >> /dev/null 2>&1; }; done;
for i in $(cat semaphores_example.txt) ; do { ipcrm -m $i >> /dev/null 2>&1; }; done;
rm semaphores_example.txt

Not found error for encodings module

You might run a Python script and get encodings module not found errors. The presence of the PYTHONHOME environment variable can lead to the mixing of Python versions:

$ python3
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x26b7980000000001 (most recent call first):
CEE5207E The signal SIGABRT was received.
ABORT instruction
This error is generally caused by setting the PYTHONHOME environment variable to a conflicting location. Try to set the PYTHONHOME environment variable and execute Python again using the following commands:
$ unset PYTHONHOME
$ python3

Errors when using distutils

  • If you see the following errors,
    FSUM3010 Specify a file with the correct suffix (.C, .hh, .i, .c, .i, .s, .o, .x, .p, .I, or .a), or a corresponding data set name....
    export the following environment variables:
    export _CC_CCMODE=1
    export _CXX_CCMODE=1
    export _C89_CCMODE=1
    export _CC_EXTRA_ARGS=1
    export _CXX_EXTRA_ARGS=1
    export _C89_EXTRA_ARGS=1
    
  • If you see the following warnings,
    WARNING CCN3236 /usr/include/unistd.h:1169  Macro name _POSIX_THREADS has been redefined.
    you can safely ignore as Python forces POSIX thread behavior in modules for compatibility reasons.
    If you see the similar error with xlc:
    "/usr/include/unistd.h", line 1169.16: CCN5848 (S) The macro name "_POSIX_THREADS" is already defined with a different definition.
    then setting the appropriate qlanglvl with redefmac can be used to work around this.

    For both xlclang and xlc, if non-POSIX thread behavior is required, you might undefine this macro in your source files. This action should be done with care and is not recommended.

  • If you see the following error while trying to install a package:
    error: [Errno 129] EDC5129I No such file or directory.: '/bin/xlc'
    This means the package that you are attempting to install requires a C compiler. If you have one in a non-standard location, you can specify it with the following command:
    CC=<path to C compiler>
    CXX=<path to C++ compiler>
    If you do not have a C/C++ compiler installed on your system, see Using IBM C/C++ compilers with IBM Open Enterprise SDK for Python 3.11 for obtaining a C/C++ compiler.

Extended precision floating point support issue in NumPy library

The NumPy library in IBM Open Enterprise SDK for Python does not support direct string conversion to the long double data type. Instead, literals and strings are parsed to a double precision floating point number followed by a conversion to the long double number. This indirect conversion introduces precision and range problems for numbers outside of the double precision range.

Errors for incorrectly tagged files

If you see an error as the following error message:
SyntaxError: Non-UTF-8 code starting with '\x84' in file test.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
ensure that the file is either encoded as ASCII or IBM-1047 and correctly tagged. The interpreter doesn't attempt to auto-detect the file encoding if the file is already tagged. If the file is correctly tagged and encoded, check the non-printable characters in the file.

Issues building and installing PyPI packages

Not all packages can be built by using the default options provided in Python, and a given PyPI package may not contain xlc compiler definitions. You can often avoid compile failures, for example, changing C standard level, by using the environment variable CFLAGS.

For packages requiring C11 and above, see Using IBM C/C++ compilers with IBM Open Enterprise SDK for Python 3.11 for obtaining the recommended compiler.

If a failure to import a library after a successful install happens, the following error message will be displayed:
Import Error: CEE3512S An HFS load of module <path to filename.so> failed. The system return code is 0000000130 and the reason code is 0BDF0C27.
A package shared library may get tagged incorrectly when using the xlc utility. Verify that the shared library is untagged by running the following line:
ls -alT <path to filename.so>
If the file is tagged, with the output being similar to the following line:
t ISO8859-1 T=on
you can remove the tag with the following command:
chtag -r <filename.so>

NumPy exec_command return value issue

The Numpy exec_command function of Numpy can be used to execute shell commands. Numpy uses the subprocess module to execute commands by using the default shell /bin/sh. While executing these commands, only the user-provided environment variables are passed to the subprocess. On z/OS, if the _BPXK_AUTOCVT environment variable is not set to ON, the default output from terminal commands might be in EBCDIC, which causes a mismatch error since the return value is expected to be in ASCII. To avoid this issue, you should follow the command line below to set an environment variable in the subprocess to get the return value in ASCII.
_BPXK_AUTOCVT='ON'

Packages unable to install cffi within a virtual environment

c/_cffi_backend.c:15:10: fatal error: 'ffi.h' file not found
The above error shows up when you try to install a package and require ffi.h file into a virtual environment without using site-packages. IBM Open Enterprise SDK for Python is distributed with several packages installed, including cffi. To get access when using a virtual environment, create the environment with the flag --system-site-packages as the following example:
<path to python3 install>/bin/python3 -m venv --system-site-packages venv

Redirecting to a file in a shell script results in garbled output

If you are redirecting to a file in a shell script and notice that the Python output is garbled, set the following environment variables:
export _TAG_REDIR_ERR=txt
export _TAG_REDIR_IN=txt
export _TAG_REDIR_OUT=txt

UnicodeDecodeError error message

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa3 in position 0: invalid start byte
This error is returned when there is a conversion error. This error message usually refers to a file that is tagged incorrectly, or has a wrong encoding specified. To verify whether the encodings are correct, see Codesets and translation for more details.

Running pip without AUTOCVT results in corrupted file generation

Running pip without AUTOCVT causes extra files to be created. These file names use conflicting encodings that results difficulty in deleting the files.

To resolve corrupt file generation, you need to set up the correct environment variables following the instructions in the IBM Open Enterprise SDK for Python documents. For more information on how to set up environment variables, refer toSet environment variables.

Specifically, you must set the following correct environment variables for auto conversion:
  • _BPXK_AUTOCVT=ON
  • _CEE_RUNOPTS= “FILETAG(AUTOCVT,AUTOTAG) POSIX(ON))”
Perform the following instructions to delete the extra files by referencing their inodes:
  1. To list the inodes corresponding to each file, use the following command:
    ls -i
    This example shows how to use the command to list the inodes associated with each file:
    $> ls -i
    215261                         	    150674 activate.fish               	213402 python3                   183585
    183584                             	150666 pip                         	213400 python3.12                215262
    325137 Activate.ps1                	150667 pip3                        	183586                    	 
    150672 activate                    	150668 pip3.12                     	277227            	 
    150673 activate.csh                	213401 python                      	183583 
  2. To delete the generated files, use the following command:
    find . -inum <insert inum> | xargs rm –f 
    This example shows the usage of command:
    $> find . -inum 215261 | xargs rm -f

Error installing PyPI package using requirements.txt file encoded in EBCDIC

When using pip to install packages through a requirements.txt file encoded in EBCDIC, you may encounter the following error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa4 in position 0: invalid start byte
To resolve the error, convert the existing EBCDIC-encoded requirements.txt file to ASCII using the following command:
iconv -T -f IBM-1047 -t ISO8859-1 requirements.txt > requirements_ascii.txt
Alternatively, you can re-create the requirements.txt file using ASCII with the following command:
pip freeze > requirements.txt