Skip to content
Advertisement

xdg-open: no method available for opening ./directory

I try to open a directory using xdg-open in Ubuntu. It works if I run xdg-open ./dir in terminal.

I have a Flask web app that opens directories using xdg-open in some situations. When I start the app from terminal in development mode (By running $ flask run ) it works and opens all directories without any problems. But when i start it in production mode using Nginx & Gunicorn it returns:

xdg-open: no method available for opening ./test

The result is exactly same as the situation that I run xdg-open in non-graphical terminal(alt+ctrl+f1)

What should I do?

Advertisement

Answer

Finally I found the solution Just I must set the $DISPLAY env variable to :0 and then run the command.

s.th like this:

env = dict(os.environ)
env['DISPLAY'] = ":0"
subprocess.Popen('xdg-open ./some_folder',env=env,shell=True)
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement