z/OS Tools & Language

Expand all | Collapse all

Python 3 usage without using .bashrc or .profile

  • 1.  Python 3 usage without using .bashrc or .profile

    Posted 05-13-2020 07:35

    we have python 3 installed and working correctly when the $PATH and $LIBPATH are set. However, as I want to use python for running Ansible against the LPAR .bashrc and .profile can’t be used.

    Ansible uses SSH remote commands to work, the equiv of:-

    ssh winmvs2c.hursley.ibm.com ‘python --version’

    How can I update USS so that python 3 is available for all users without relying on .bashrc or .profile and will work with non-interactive SSH sessions?

    Michael Baylis
    IBM Senior Software Engineer - CICS TS

  • 2.  RE: Python 3 usage without using .bashrc or .profile

    Posted 05-13-2020 12:09

    You can set PATH as part of the ssh command.
    for example,

    ssh pdharr@rs25 PATH=/u/pdharr/miniconda/bin:/bin XYZ=a python -c “’”‘import os; print(os.getenv(“XYZ”))’"’"

    will print

    Rick Harris
    Rocket Software

  • 3.  RE: Python 3 usage without using .bashrc or .profile

    Posted 05-19-2020 11:53

    Hi Rick, that has worked thank you. Makes the anisble host inventory a bit messy:-

    ansible_python_interpreter: ‘PATH=/python/v361/python-2017-04-12-py36/python36/bin:/usr/bin:/bin:/usr/sbin LIBPATH=/python/v361/python-2017-04-12-py36/python36/lib:/lib:/usr/lib python’

    Would be nice if somehow in USS we can set this, but I can’t find it.

  • 4.  RE: Python 3 usage without using .bashrc or .profile

    Posted 05-25-2020 08:00

    Hello Michael,

    I’m not that good at Ansible so a couple of questions first:

    1. What’s your default shell - is it /bin/sh or bash?

    2. Is there a reason why you can’t use .bashrc (provided your default shell is bash) ? My understanding is that it gets executed on non-interactive logons as well.

    3. If you already have PATH/LIBPATH in .profile or some other script, can’t you just run that script before invoking python? Something like this:

    ssh user@host '. ~/.profile; python --version'