79523185

Date: 2025-03-20 14:06:48
Score: 3
Natty:
Report link

I don't think this is the ideal approach, but I was able to get this to work.

  1. On the terminal, go into pipenv shell

  2. Copy the path that is output from which python3

  3. In native_host.py, include the following to run the app.

import os
os.system("/Users/bernadette/.local/share/virtualenvs/convert_and_combine_pdfs-mqF7aRtH/bin/python3 ./some_script.py")

What seemed to make the difference was externally(?) accessing the virtual environment. But it doesn't seem to handle sending the native host's response back properly.

Setting .venv in the root of the project and running pipenv shell allowed me to create a relative path to the necessary version of python.

  • Is a script within a script the only way to get this working?

It seems so. The third party and app modules were only able to import from the called script.

  • subprocess.call("...") didn't seem to work, is there a way to use that instead of os.system?

I used subprocess.Popen instead. Setting stdout handled issues related to print interfering with the process.

The final code:

process = subprocess.Popen(
        [
            ".venv/bin/python3",
            "./some_script.py",
            json.dumps(receivedMessage),
        ],
        stdout=subprocess.PIPE
    )
    stdout, stderr = process.communicate()
Reasons:
  • Blacklisted phrase (1): is there a way
  • RegEx Blacklisted phrase (2): working?
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Boom100100