Why does this python script not run when executed from my batch file?

  batch-file, python, windows

I have a batch file set up to run a ghostscript which creates a .pdf output, which I then want to use in a subsequent python script. The batch file itself runs without issue and looks like this:

"%PROGRAMFILES%gsgs9.54.0bingswin64c.exe" -dBATCH -dSAFER -dNOPAUSE -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dAutoRotatePages=/PageByPage -r600 -sOutputFile=%~dp0%result%.pdf -
"%~dp0test.py" %result%.pdf

The batch file log shows that it executes all commands. Furthermore, a dummy python script that does nothing but log that it ran also works perfectly. However, when I substitute the dummy for the script I want to use, the file does not do what it should, despite running perfectly when run on its own from the console. The python script looks like this:

import os
import sys
from rmapy.document import ZipDocument
from rmapy.api import Client
# sets up the current directory to be the same as the .py file

# sets up the remarkable api

# finds the pdf
for arg in sys.argv[1:]:
    rawDocument = ZipDocument(doc=arg)

I highly appreciate any help you are able to offer. I suspect there is something in the .py file that produces an error when called through the batch file, but I can’t figure out what.

Source: Windows Questions