Python problem

Clovertech Forums Cloverleaf Python problem

  • Creator
    Topic
  • #120873
    David Barr
    Participant

      I’m trying out Python 3 (jep) with Cloverleaf 20.1.2. Is there a way to install modules such as the “hl7” module from PyPI?

      I haven’t figured out how to get a command line prompt from jep. Is this possible?

      I printed out “sys.path” from within a TPS function, and it listed a bunch of system python 3.8 folders, so I used “pip3.8 install hl7” which installed the module in /usr/local/lib/python3.8/site-packages. However, if I try to import it from my TPS function, I get an error, and it seems to be related to the module requiring the math module. If I try to “import math” in my TPS function I get the same error (clImport() failed. Exception:/usr/lib64/python3.8/lib-dynload/math.cpython-38-x86_64-linux-gnu.so: undefined symbol: PyExc_ValueError). I tried to include the full error but I keep having problems posting it to this forum.

      Also, the engine process that I’m running this proc in is also crashing with a panic whenever I stop the process.

    Viewing 3 reply threads
    • Author
      Replies
      • #120876
        David Barr
        Participant

          I’m thinking the math module problem could be because I’m using Python 3.8 from the Redhat 8 repositories rather than from Github. I may try switching that to see if it makes a difference. Also, someone recommended I try the “hl7apy” module rather than the “hl7” module. I’m working on a Cloverleaf upgrade, so I may not worry about 20.1.2 and just get it working on 2022.09.01.

        • #121322
          Ramachandran R
          Participant

            Dear David,
            Were you able to get this working, as we are having the same issue in both Cloverleaf 20.1.2 and 20.1.3. The Set up our Cloverleaf, platform, and Python version are the same as yours.

            Thank you.

          • #121344
            Ramachandran R
            Participant

              I just made it work in our Cloverleaf 20.1.3.  Just for the documentations, provided below the steps,

              Please download and try with the cpython from https://github.com/indygreg/python-build-standalone/releases/download/20230826/cpython-3.8.17+20230826-x86_64-unknown-linux-gnu-install_only.tar.gz

              Unzip the package (assuming the path is $PYTHON_PATH) and add $PYTHON_PATH/bin to $PATH, add $PYTHON_PATH/lib to $LD_LIBRARY_PATH

              Validate which python is being used by hci user, it needs to be the path you had just set up.

              You may need to install all the python packages again and try from Cloverleaf

            • #121501
              David Barr
              Participant

                I’ve had Python 3 scripts working as TPS procs for a while. As you pointed out, you need to have PATH and LD_LIBRARY_PATH updated to include the cpython folder. It looks like I’m using version 3.8.12 which was referred to in one of the install guides, and it works. I’m currently on Cloverleaf 2022.09.03.

                The problem I have is that I’m setting PATH and LD_LIBRARY_PATH in /etc/profile. That works when I start the engine processes from a shell prompt, but it doesn’t work when I use the supplied autostart scripts called from /usr/lib/systemd/system/cloverleaf-autostart.service.

                Do you know how I can get the environment set up so that the autostart service has LD_LIBRARY_PATH set correctly when called on system startup?

                • This reply was modified 5 months, 4 weeks ago by David Barr.
                • This reply was modified 5 months, 4 weeks ago by David Barr.
                • #121504
                  David Barr
                  Participant

                    It looks like maybe I could add the environmental variables to /home/hci/.bashrc, but I would probably have to add them to the very top, because the file starts with these lines:

                    # .bashrc
                    # Add the following to the top of the ~/.bashrc for user hci
                    # Added this to handle non-interactive access (ie. SCP)
                    # The result will be the ‘.profile’ will be skipped when not helpful
                    [[ -z “$PS1” ]] && return # non-interactive
                    [[ $- =~ i ]] || return # non-interactive
                    tty -s || return # non-interactive

                    I think if I don’t put the variables above those lines then they would be skipped when running the commands from the systemd script. I may have to test this.

                  • #121512
                    Ramachandran R
                    Participant

                      Yes, this is how we also managed to do.

                    • #121515
                      David Barr
                      Participant

                        Modifying bashrc alone didn’t solve my issue. The variables were not getting picked up by the autostart process. I opened a support ticket, and this was the resolution:

                        R&D suggested to try to add the path in /usr/lib/systemd/system/cloverleaf-autostart.service in line 3 and 4 before “export“ like:

                        /usr/bin/bash -c “export PATH=yourpythonpath:$PATH export LD_LIBRARY_PATH=yourpythonpath:$LD_LIBRARY_PATH export …..”

                  Viewing 3 reply threads
                  • You must be logged in to reply to this topic.