'Error when using Google Cloud vision and pm2 with python3 script

I'm trying to run my script on a unbuntu server. One the the libraries the script requires is Google Cloud Vision. It works locally and on the server if I use the python3 command - it only throws this error when running with pm2.

Before running the pm2 command, I enter the following: export GOOGLE_APPLICATION_CREDENTIALS=ocr_keys.json.

Following this command I type: pm2 start controller.py --interpreter python3

When I then type pm2 log I get the following:

0|controll |   File "/root/planned2/bio.py", line 10, in <module>
0|controll |     from timeline import image_ocr, safe_status
0|controll |   File "/root/planned2/timeline.py", line 16, in <module>
0|controll |     OCR_CLIENT = vision.ImageAnnotatorClient()
0|controll |   File "/usr/local/lib/python3.6/dist-packages/google/cloud/vision_v1/gapic/image_annotator_client.py", line 165, in __init__
0|controll |     address=api_endpoint, channel=channel, credentials=credentials
0|controll |   File "/usr/local/lib/python3.6/dist-packages/google/cloud/vision_v1/gapic/transports/image_annotator_grpc_transport.py", line 70, in __init__
0|controll |     "grpc.max_receive_message_length": -1,
0|controll |   File "/usr/local/lib/python3.6/dist-packages/google/cloud/vision_v1/gapic/transports/image_annotator_grpc_transport.py", line 109, in create_channel
0|controll |     address, credentials=credentials, scopes=cls._OAUTH_SCOPES, **kwargs
0|controll |   File "/usr/local/lib/python3.6/dist-packages/google/api_core/grpc_helpers.py", line 177, in create_channel
0|controll |     credentials, _ = google.auth.default(scopes=scopes)
0|controll |   File "/usr/local/lib/python3.6/dist-packages/google/auth/_default.py", line 321, in default
0|controll |     raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
0|controll | google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started

Any help is appreciated!

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source