I use the function “Execute Shell Script / Task” to execute a python script.
The python script imports the module psycopg2.
Based on the discussion here, I have set a environment variable as follows:
PYTHONPATH=/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/
But I still encounter the following error in BTC:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/psycopg2/__init__.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
ModuleNotFoundError: No module named 'psycopg2._psycopg'
Please note that the script runs flawlessly in Terminal.
I can also import psycopg2 in Terminal (and confirm that psycopg2 does have a module called psycopg).
So the error does not come from a bad installation of psycopg2.
Current params are the following:
LaunchPath: /usr/local/bin/python3
Parameters: None
Env: PYTHONPATH=/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/
Script: path_to_file/file.py
Yes, it does work.
I keep on looking for a typo somewhere, but I can't find any.
I copy-pasted in Terminal the following command: /usr/local/bin/python3 path_to_file/file.py
I did with 2 different files (pointing at 2 different dbs): worked both times.
Puzzling.
Adding the -q flag did have a positive effect: the script started!
Unfortunately, the script (backup of a local db) gets stuck again.
Same outcome as with attempt n°5/11, above (with import sys).
The function is a simple wrapper around pg_dump.
Yet the backup gets never produced.
(The script works flawlessly when I run it through Terminal).
Weird, is it maybe expecting some other environment variables? In general there shouldn't be a difference apart from the environment variables I think.