the solution to the issue to add a “load python script” prior to my big code, which imports certain libraries, in order to run my other code. so basically had to split it
For me, import codecs didn’t help but when I saved my Python code as ISO-8859-1 instead of UTF-8 (had to replace the Scandinavian characters that caused issues with UI Path in the process), then UI Path loaded the script without any issues.