Skip to main content
New Participant
Jul 31, 2023 12:10 PM UTC
Question

Why isn't Python working as expected?

I've installed Rocket Open AppDev for Z (free solution), but Python doesn't seem to be working quite right.

In particular, I'm getting different behavior based on whether I invoke Python via executing the script vs. invoking Python manually and passing it the script.  For example, with the following sample test.py:

#!/z/rocket/tools/bin/python

print("Hello world!")

If I invoke Python explicitly and pass it the script, it works just fine:

$ /z/rocket/tools/bin/python test.py

Hello world!

If I instead invoke the script directly, I get the following.

$ ./test.py

./test.py: can't open file '/u/z123/SHELL=/z/rocket/tools/bin/bash': [Errno 129] EDC5129I No such file or directory.

That looks like it's somehow interpreting the environment being passed to python ("SHELL=...") as the script name it's supposed to execute.  Indeed, if I then pass the script name as the first argument, it works:

$ ./test.py test.py

Hello world!

Stranger still, I don't see this behavior with scripts that invoke /bin/sh or /z/rocket/tools/bin/bash.

The following environment variables seem to be correctly set:

_BPXK_AUTOCVT=ON

_CEE_RUNOPTS=FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)

PATH=/z/rocket/tools/condabin:/z/rocket/tools/bin:/bin:.

Changing the value of _BPX_SPAWN_SCRIPT doesn't change the behavior either.

Any ideas?

    3 replies

    Alexander Klochkov
    Rocketeer
    Aug 1, 2023 9:28 AM UTC

    I've installed Rocket Open AppDev for Z (free solution), but Python doesn't seem to be working quite right.

    In particular, I'm getting different behavior based on whether I invoke Python via executing the script vs. invoking Python manually and passing it the script.  For example, with the following sample test.py:

    #!/z/rocket/tools/bin/python

    print("Hello world!")

    If I invoke Python explicitly and pass it the script, it works just fine:

    $ /z/rocket/tools/bin/python test.py

    Hello world!

    If I instead invoke the script directly, I get the following.

    $ ./test.py

    ./test.py: can't open file '/u/z123/SHELL=/z/rocket/tools/bin/bash': [Errno 129] EDC5129I No such file or directory.

    That looks like it's somehow interpreting the environment being passed to python ("SHELL=...") as the script name it's supposed to execute.  Indeed, if I then pass the script name as the first argument, it works:

    $ ./test.py test.py

    Hello world!

    Stranger still, I don't see this behavior with scripts that invoke /bin/sh or /z/rocket/tools/bin/bash.

    The following environment variables seem to be correctly set:

    _BPXK_AUTOCVT=ON

    _CEE_RUNOPTS=FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)

    PATH=/z/rocket/tools/condabin:/z/rocket/tools/bin:/bin:.

    Changing the value of _BPX_SPAWN_SCRIPT doesn't change the behavior either.

    Any ideas?

    Hello John,

    Can you share the output of the following commands:

    python --version

    env | sort

    Thanks,

    Alexander

    Jorn Thyssen
    Rocketeer
    Aug 2, 2023 8:44 AM UTC

    I've installed Rocket Open AppDev for Z (free solution), but Python doesn't seem to be working quite right.

    In particular, I'm getting different behavior based on whether I invoke Python via executing the script vs. invoking Python manually and passing it the script.  For example, with the following sample test.py:

    #!/z/rocket/tools/bin/python

    print("Hello world!")

    If I invoke Python explicitly and pass it the script, it works just fine:

    $ /z/rocket/tools/bin/python test.py

    Hello world!

    If I instead invoke the script directly, I get the following.

    $ ./test.py

    ./test.py: can't open file '/u/z123/SHELL=/z/rocket/tools/bin/bash': [Errno 129] EDC5129I No such file or directory.

    That looks like it's somehow interpreting the environment being passed to python ("SHELL=...") as the script name it's supposed to execute.  Indeed, if I then pass the script name as the first argument, it works:

    $ ./test.py test.py

    Hello world!

    Stranger still, I don't see this behavior with scripts that invoke /bin/sh or /z/rocket/tools/bin/bash.

    The following environment variables seem to be correctly set:

    _BPXK_AUTOCVT=ON

    _CEE_RUNOPTS=FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)

    PATH=/z/rocket/tools/condabin:/z/rocket/tools/bin:/bin:.

    Changing the value of _BPX_SPAWN_SCRIPT doesn't change the behavior either.

    Any ideas?

    I use: 

    #!/usr/bin/env python3

    New Participant
    Aug 3, 2023 2:39 PM UTC

    I've installed Rocket Open AppDev for Z (free solution), but Python doesn't seem to be working quite right.

    In particular, I'm getting different behavior based on whether I invoke Python via executing the script vs. invoking Python manually and passing it the script.  For example, with the following sample test.py:

    #!/z/rocket/tools/bin/python

    print("Hello world!")

    If I invoke Python explicitly and pass it the script, it works just fine:

    $ /z/rocket/tools/bin/python test.py

    Hello world!

    If I instead invoke the script directly, I get the following.

    $ ./test.py

    ./test.py: can't open file '/u/z123/SHELL=/z/rocket/tools/bin/bash': [Errno 129] EDC5129I No such file or directory.

    That looks like it's somehow interpreting the environment being passed to python ("SHELL=...") as the script name it's supposed to execute.  Indeed, if I then pass the script name as the first argument, it works:

    $ ./test.py test.py

    Hello world!

    Stranger still, I don't see this behavior with scripts that invoke /bin/sh or /z/rocket/tools/bin/bash.

    The following environment variables seem to be correctly set:

    _BPXK_AUTOCVT=ON

    _CEE_RUNOPTS=FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)

    PATH=/z/rocket/tools/condabin:/z/rocket/tools/bin:/bin:.

    Changing the value of _BPX_SPAWN_SCRIPT doesn't change the behavior either.

    Any ideas?

    I've since discovered that IBM's Python does the same thing.  Its documentation mentioned the need for /usr/bin/env, so I made sure that was present and changed my script to start with "#!/usr/bin/env python" ... and that works.

    So I can use that approach for my scripts, but all of the scripts installed by Rocket installer break, because they all start with "#!/z/rocket/tools/bin/python".  

    I seem to be the first person to encounter this, so clearly there's something strange about my system...

    $ /z/rocket/tools/bin/python --version

    Python 3.10.7

    $ /usr/lpp/IBM/cyp/v3r10/pyz/bin/python --version

    Python 3.10.12

    $ env | sort

    ASCII_TERMINFO=/z/rocket/tools/share/terminfo
    CURL_CA_BUNDLE=/z/rocket/tools/etc/ssl/cacert.pem
    FFI_LIB=/z/rocket/tools/lib/ffi
    HOME=/u/user
    LANG=C
    LC_ALL=C
    LIBPATH=/z/rocket/tools/lib:/lib:/usr/lib:.:/usr/lpp/IBM/zoautil/lib
    LOGNAME=USER
    MAIL=/usr/mail/USER
    MANPATH=/z/rocket/tools/share/man:/usr/man/%L:/usr/lpp/IBM/zoautil/docs/%L
    NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/%L/%N.cat
    OPENSSL_CONF=/z/rocket/tools/bin/openssl.cfg
    PAGER=/bin/more
    PATH=/usr/bin:/z/rocket/tools/bin:/bin:.:/usr/lpp/IBM/zoautil/bin
    PS1=[u@h w]$ 
    PWD=/u/user
    SHELL=/z/rocket/tools/bin/bash
    SHLVL=0
    SSH_CLIENT=XXXX
    SSH_CONNECTION=XXXX
    SSH_TTY=/dev/ttyp0000
    SSL_CERT_DIR=/z/rocket/tools/ssl/certs
    STEPLIB=none
    TERM=xterm
    TZ=CST6CDT
    USER=USER
    ZOAU_HOME=/usr/lpp/IBM/zoautil
    _=/usr/bin/env
    _BPXK_AUTOCVT=ON
    _CEE_RUNOPTS=FILETAG(AUTOCVT,AUTOTAG) POSIX(ON) HEAPP(ON,8,10,32,10,128,10,256,10,1024,10,2048,10,0,10,0,10,0,10,0,10,0,10,0,10)
    _TAG_REDIR_ERR=txt
    _TAG_REDIR_IN=txt
    _TAG_REDIR_OUT=txt