Python - Group home

Installing PyPI Packages with C components on Python 3.12

  

This blog was originally written in response to compatibility with z/OS C/C++ compilers not being merged into the latest setuptools at the time. The required changes were merged and released in setuptools v69.4.0. If you are still hitting the errors mentioned within this blog, verify that the setuptools version being used in your package is at or above this version. The original blog is left unchanged below.

----------------

IBM Open Enterprise SDK for Python 3.12 follows the Python community's direction and drops support for the distutils package in favor of setuptools for building packages. Currently, support for building z/OS has not been merged into the latest setuptools release, and depending on the compiler that is being used, you will see one of the following errors when trying to build a package that requires a C compiler. 

These failures are expected to be temporary - when support for z/OS C compilers has been added into setuptools, these errors will no longer occur. In the meantime, this blog provides some environment variables that can be set to allow packages using setuptools with C components to be built when using pip. Note that this also only applies to IBM Open Enterprise SDK for Python 3.12, and not any of the previous versions.  

If you see the following error:

error: command '/usr/lpp/IBM/oelcpp/v2r0/bin/clang' failed: EDC5129I No such file or directory. 

Then you do not have the C compiler installed, or it has been installed at a different location. You can follow the docs Using IBM C/C++ compilers with IBM Open Enterprise SDK for Python 3.12 to either install a C compiler, or set the environment variables CC, CXX, and LDSHARED appropriately to point to your installed C compiler.  

If you see the following error: 

FSUM3248 xlclang: Directory /usr/lpp/IBM/cyp/v3r12/pyz/lib specified by command option -L cannot be searched. 

Then you can set the environment variable LDSHARED to use IBM z/OS XL C/C++ with the following to fix this: 

export LDSHARED=/bin/xlc 

 

If you are seeing errors similar to the following:

IEW2456E 9207 SYMBOL PyModule_Create2 UNRESOLVED.  MEMBER COULD NOT BE INCLUDED 
         FROM THE DESIGNATED CALL LIBRARY. 
IEW2456E 9207 SYMBOL _PyArg_ParseTupleAndKeywords_SizeT UNRESOLVED.  MEMBER 
         COULD NOT BE INCLUDED FROM THE DESIGNATED CALL LIBRARY. 
IEW2456E 9207 SYMBOL _Py_NoneStruct UNRESOLVED.  MEMBER COULD NOT BE INCLUDED 
         FROM THE DESIGNATED CALL LIBRARY. NAME SPACE = 3 
IEW2456E 9207 SYMBOL PyExc_OSError UNRESOLVED.  MEMBER COULD NOT BE INCLUDED 
         FROM THE DESIGNATED CALL LIBRARY. NAME SPACE = 3 
IEW2456E 9207 SYMBOL PyErr_SetFromErrno UNRESOLVED.  MEMBER COULD NOT BE 
         INCLUDED FROM THE DESIGNATED CALL LIBRARY. 
IEW2456E 9207 SYMBOL _PyArg_ParseTuple_SizeT UNRESOLVED.  MEMBER COULD NOT BE 
         INCLUDED FROM THE DESIGNATED CALL LIBRARY. 
IEW2456E 9207 SYMBOL _Py_BuildValue_SizeT UNRESOLVED.  MEMBER COULD NOT BE 
         INCLUDED FROM THE DESIGNATED CALL LIBRARY. 
IEW2456E 9207 SYMBOL PyBool_FromLong UNRESOLVED.  MEMBER COULD NOT BE INCLUDED 
         FROM THE DESIGNATED CALL LIBRARY. 
IEW2665S 40FF MODULE *NULL*  IS NON-EXECUTABLE AND WAS NOT SAVED BECAUSE 
         STORENX=NEVER. 

 

ERROR CCN3205 /usr/lpp/IBM/cyp/v3r12/pyz/include/python3.12/pyport.h:593   "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)." 
ERROR CCN3277 /usr/lpp/IBM/cyp/v3r12/pyz/include/python3.12/object.h:210   Syntax error: possible missing ';' or ','? 
ERROR CCN3485 /usr/lpp/IBM/cyp/v3r12/pyz/include/python3.12/object.h:210   Parameter declaration list is incompatible with declarator for inline. 
ERROR CCN3045 /usr/lpp/IBM/cyp/v3r12/pyz/include/python3.12/object.h:220   Undeclared identifier ob. 

Then these can be resolved by exporting the appropriate environment variables for the C compiler that you are using, seen below, then running your pip install command again. Note that LDFLAGS contains the path to the default SMP/E install location - if you are using the pax version, the path will need to be prefixed by the location of your install. There is a full example of this at the bottom of this blog.

 

For using IBM C/C++ For Open Enterprise Languages on z/OS 2.0 or IBM Open XL C/C++ 1.1 for z/OS:

export CFLAGS="-m64 -fvisibility=default -fzos-le-char-mode=ascii -fno-short-enums" 
export LDFLAGS="/usr/lpp/IBM/cyp/v3r12/pyz/lib/libpython3.12.x" 

 

For using IBM XL C/C++ 2.4.1 for z/OS 2.4 and z/OS 2.5:

export CFLAGS="-q64 -qexportall -qascii -qstrict -qnocsect -Wa,asa,goff -Wa,xplink -qgonumber -qenum=int -Wc,DLL" 
export LDFLAGS="-Wl,dll -q64 /usr/lpp/IBM/cyp/v3r12/pyz/lib/libpython3.12.x" 

 

For using IBM z/OS XL C/C++:

export CFLAGS="-q64 -qexportall -qascii -qstrict -qnocsect -Wa,asa,goff -Wa,xplink -qgonumber -qenum=int -Wc,DLL -qlanglvl=extc99" 
export LDFLAGS="-Wl,dll -q64 /usr/lpp/IBM/cyp/v3r12/pyz/lib/libpython3.12.x" 

  

A full sample of building a package that requires a C compiler using the pax install of IBM Open Enterprise SDK for Python 3.12 with IBM Open XL C/C++ 1.1 for z/OS: 

# Set required Python environment variables 
# Python is installed at /home/pitman/usr/lpp/IBM/cyp/v3r12/pyz 
export PATH=/home/pitman/usr/lpp/IBM/cyp/v3r12/pyz/bin:$PATH 
export LIBPATH=/home/pitman/usr/lpp/IBM/cyp/v3r12/pyz/lib:$LIBPATH 
export _BPXK_AUTOCVT='ON' 
export _CEE_RUNOPTS='FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)' 
export _TAG_REDIR_ERR=txt 
export _TAG_REDIR_IN=txt 
export _TAG_REDIR_OUT=txt   

# Set the C compiler to use IBM Open XL C/C++ 1.1 for z/OS 
export CC=/usr/lpp/IBM/cnw/v1r1/openxl/bin/ibm-clang64 
export CXX=/usr/lpp/IBM/cnw/v1r1/openxl/bin/ibm-clang++64 
export LDSHARED=/usr/lpp/IBM/cnw/v1r1/openxl/bin/ibm-clang64 

# Set temporary workaround CFLAGS & LDFLAGS 
export CFLAGS="-m64 -fvisibility=default -fzos-le-char-mode=ascii -fno-short-enums" 
export LDFLAGS="/home/pitman/usr/lpp/IBM/cyp/v3r12/pyz/lib/libpython3.12.x" 

# Install zos-util package 
pip3 install zos-util