I have installed qpdf and am trying to call it via Python.
I have added the path to my system Environment Variables and can successfully run the following command via the command prompt:
qpdf --decrypt input.pdf output.pdf
This runs, no issues.
However, when trying to call via Python (code from here), I get
'qpdf' is not recognized as an internal or external command, operable program or batch file.
import subprocess
subprocess.call(["cmd", "/c", "qpdf --decrypt input.pdf output.pdf"], shell=True)
# or
subprocess.run(["qpdf", "--decrypt", "input.pdf", "output.pdf"], shell=True)
# or
subprocess.run(["qpdf --decrypt input.pdf output.pdf"], shell=True)
Why can I run this via cmd, but not in Python?
As per the comments:
The problem is that environment variables are only loaded when you launch your executable/shell session/whatever. Here, a directory was added to the PATH environment variable, so sublime text needed to be restarted before it could see the updated PATH. This isn't specific to sublime, the same would be true if you were running directly from a terminal or another IDE.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With