Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8163443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:03:30+00:00 2026-06-06T19:03:30+00:00

I want to set up a cron job to run a python script, but

  • 0

I want to set up a cron job to run a python script, but it gives me this error:

RuntimeError: could not open display

This is because I import a module that requires me to open display (pylab, for example). Even though my script does not generates any pictures to display on the monitor.

Is there any way to let crontab run my jobs with display open (just as if I ssh -X into a machine)? I don’t actually need to generate any graphs to the monitor. I just need to import my modules correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:03:32+00:00Added an answer on June 6, 2026 at 7:03 pm

    You will need a valid DISPLAY and XAUTHORITY to use X-Programms in Cron!

    To set DISPLAY is very easy, type in the Bash:

    export DISPLAY=":0.0"
    

    In order to get a valid XAUTHORITY you have to look for it.
    Under Debian/Gnome/gdm3 they are saved in var/run/gdm3/*/database
    I used the following script:

    export DISPLAY=":0.0"
    [ -z $USER ] && USER=$( who | awk '{ print $1 }' | sort | uniq >/tmp/test )
    for I in /var/run/gdm3/*; do
        AUTHUSER="`echo $I | awk -F '-' '{ print $3 }'`"
        for J in $USER; do
            [ "${AUTHUSER}" = "${J}" ] || continue
            USER="$J"
            export XAUTHORITY="${I}/database" && break
        done
    done
    sudo -u ${USER} /Path/to/xProgramm
    

    The Var $USER can be empty, than the script looks for a valid user, otherwise you can tell the script the var!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to add a cron job thru a script I run to set
I want to set up a cron job. The job has to run every
I want set Listbox background to transparent but not working Is there any idea?
I want to set the cron job in the config file of the Catalog
I've set up a cron job via my hosting account's cPanel. This basically calls
I have Linux, PHP installed. I want to set the cron job which will
I want set run a file with cron at 12:03:37 every day. How do
I want to setup a Cron job to run a django file. What I
I want to set a cron job that will execute every 15 minutes. Before
I want to set up a cron job which will execute a command every

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.