I don't think this is the ideal approach, but I was able to get this to work.
On the terminal, go into
pipenv shell
Copy the path that is output from
which python3
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 ofos.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()