Answer the question
In order to leave comments, you need to log in
How to fix "vncserver: The HOME environment variable is not set" error - run python script from PHP as user?
I run the Python
script from PHP . The script starts normally, but when it reaches the vncserver start lines , it cannot start it:
#!/usr/bin/env python3.8
# -*- coding: UTF-8 -*-
import time
import requests
from datetime import datetime
from pymongo import MongoClient
from multiprocessing import Pool
import json
import math
import subprocess
import os
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
.
.
.
## VNC Display checks
# Configure DISPLAY variable to VNC
os.environ["DISPLAY"] = cfg["vnc_display"]
if os.system("xhost >& /dev/null"):
print("WARNING: No VNC display opened under %s. Running VNC Server and trying again" % (os.environ["DISPLAY"]))
os.system("vncserver %s" % (os.environ["DISPLAY"]))
time.sleep(5)
if os.system("xhost >& /dev/null"):
print("ERROR: No VNC display opened under %s. Cannot continue" % (os.environ["DISPLAY"]))
return
.
.
.
if __name__ == "__main__":
command_line_runner()
Answer the question
In order to leave comments, you need to log in
Did it like this:
.
.
.
from os.path import expanduser
HOME = expanduser("~")
.
.
.
os.environ["HOME"] = HOME
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question