Adding both the "bin" and "lib" paths for Ghostscript to the PATH worked for me:
C:\Program Files\gs\gs9.26\bin
C:\Program Files\gs\gs9.26\lib
Then you will need to apply that change, depending on the specific use case.
In order of severity
- Restart Python - this should just work
- Have Python obtain Gostscript automatically and update the running environment
- Reboot if you can and as a last resort
Generally and without going into each OS and each environment running the Python interpreter (e.g. Jupyter session, IDE or CLI), a reboot is normally excessive. For some a reboot is not even possible.
Just close and re-open your environment (defined above) after the app installer completes or you have altered the PATH yourself.
There is nothing stopping you from altering the PATH within your Python script using the subprocess module to install the additional application or the os module, or by referencing the apps absolute path e.g.
# Updating the current PATH inside Python
import os
from pathlib import Path
def update_app_path(app, new_path):
# Get the PATH environment variable
existing = [Path(p) for p in os.environ["PATH"].split(os.path.pathsep))
# Copy it, deleting any paths that refer to the application of interest
new_path = [e for e in existing if not Path(e/app).exists()]
# Append a the new entry
new_path.append(new_path)
# or you could use new_path.append(Path(new_path).parent)
# Reconstruct and apply the PATH
os.environ["PATH"] = os.path.pathsep.join(map(str, new_path))
This works as Python takes a copy of the current environment when it starts and anything it then does after that, using os or shell calls, uses that copied environment. Altering the environment within Python does not change the user's environemnt outside of that running Python, and changes in this way are not permanent unless deliberately made so.