Error Loading Python Script: "Module sys has no attribute 'argv'"

Why is loading python script failing with error "Sys has no argument 'argv'"?

Issue Description

When a library is used with embedded Python (e.g. Postgres extension written in C calling Python, like Multicorn), sys.argv is not defined, which makes the library misbehave.

Resolution

Assign an empty string to the sys.argv value, as given below, while importing the same and it should work.

import sys

if not hasattr(sys, ‘argv’):
sys.argv = [‘’]