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.
As mentioned earlier, the script works fine when I run directly from Terminal, ie:
python3 /path_to_file/file.py
Thank you!
I tried specifying the PATH variable for python3, but seem to be getting the same error. Am I missing something obvious? I also tried $PATH and both with/without parentheses around the folder.
That looks promising.
What would be the syntax, for pointing to a .py file in the script box?
I tried the absolute path, namely /path_to_file/file.py
I get the following error:
File "<string>", line 1
/path_to_file/file.py
SyntaxError: invalid syntax
With Launch Path set as "/usr/local/bin/python3", I did try the following:
# https://www.geeksforgeeks.org/python-import-module-from-different-directory/
import sys
folder = "path_to_folder"
sys.path.append(folder)
from file import function
function()
Unfortunately, the script (backup of a local db) gets stuck.
The only workaround I found is to:
open a Terminal window
paste the python3 command.
No error, but nothing happens
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.
I think there is a bug in BTT if no parameters are provided. I'll fix that.
Could you try to pass some parameter that doesn't have any meaning in this scenario, e.g. -q
image2738×1674 260 KB
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).