I would recommend exporting environment variables directly to your terminal as they are often set too late in the Python script and this won’t be read again.
Certain environment variables are read only during the import of a library and often users set them too late, which can cause confusion.
For this reason, I would not recommend setting any environment variables inside the Python script but to properly export them in your terminal before launching the Python process.