Run 'freecad -c' from php throws error qt.qpa.xcb: could not connect to display

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
agustavo87
Posts: 10
Joined: Tue Jul 05, 2022 4:17 pm

Re: Run 'freecad -c' from php throws error qt.qpa.xcb: could not connect to display

Post by agustavo87 »

adrianinsaval wrote: Mon Sep 05, 2022 12:17 pm Seems you have some sort of permission error, you should run it with the --write-log option an upload the log
  • freecad.AppImage -c --write-log "print(2+2)" 2>&1

    Code: Select all

    File exists and file size matches, skipping 
    File exists and file size matches, skipping 
    [... a lot more of that ...]
    qt.qpa.xcb: could not connect to display qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found. 
    This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. 
    Available platform plugins are: eglfs, minimal, minimalegl, offscreen, vnc, webgl, xcb. 
    /tmp/appimage_extracted_8cac30c456e0f6469e8601386557085d/AppRun: line 42: 2914 Aborted ${MAIN} "$@"
    
  • freecad.AppImage freecadcmd -c --write-log "print(2+2)" 2>&1

    Code: Select all

    File exists and file size matches, skipping 
    File exists and file size matches, skipping 
    [... a lot more of that ...]
    Initialization of FreeCAD failed: While initializing FreeCAD the following exception occurred: 
    'Could not create directories. Failed with: Permission denied' Python is searching for its runtime files in the following directories:
    /tmp/appimage_extracted_8cac30c456e0f6469e8601386557085d/usr/lib/python39.zip:/tmp/appimage_extracted_8cac30c456e0f6469e8601386557085d/usr/lib/python3.9:/tmp/appimage_extracted_8cac30c456e0f6469e8601386557085d/usr/lib/python3.9/lib-dynload 
    Python version information: 3.9.13 | packaged by conda-forge | (main, May 27 2022, 17:07:55) [GCC 10.3.0] 
    The environment variable PYTHONHOME is set to '/tmp/appimage_extracted_8cac30c456e0f6469e8601386557085d/usr'. Setting this environment variable might cause Python to fail. Please contact your administrator to unset it on your system.
    
There seems to be no log.
User avatar
amrit3701
Posts: 343
Joined: Mon Jun 13, 2016 5:37 pm

Re: Run 'freecad -c' from php throws error qt.qpa.xcb: could not connect to display

Post by amrit3701 »

agustavo87 wrote: Mon Sep 05, 2022 11:14 am
  • freecad.AppImage freecadcmd -c "print(2+2)"
    - from Shell
    4
    - from HTTP
    Initialization of FreeCAD failed: While initializing FreeCAD the following exception occurred: 'Could not create directories. Failed with: Permission denied' Python is searching for its runtime files in the following directories: /tmp/appimage_extracted_8cac30c456e0f6469e8601386557085d/usr/lib/python39.zip:/tmp/appimage_extracted_8cac30c456e0f6469e8601386557085d/usr/lib/python3.9:/tmp/appimage_extracted_8cac30c456e0f6469e8601386557085d/usr/lib/python3.9/lib-dynload Python version information: 3.9.13 | packaged by conda-forge | (main, May 27 2022, 17:07:55) [GCC 10.3.0] The environment variable PYTHONHOME is set to '/tmp/appimage_extracted_8cac30c456e0f6469e8601386557085d/usr'. Setting this environment variable might cause Python to fail. Please contact your administrator to unset it on your system.

Yes, these are permission errors. When you normally run freecad.AppImage freecadcmd "print(2+2)” from shell then you execute program as $USER but when you running same over HTTP request then user is www-data and freecad.AppImage freecadcmd "print(2+2)” command creates a temporary folder in /tmp path and www-data user don't have enough permissions to create that folder.

To replicate issue on command line, login to www-data user (command: su -s /bin/bash www-data), and then run freecad.AppImage freecadcmd "print(2+2)”.

I would suggest to unpack AppImage, give all required permissions and then run freecadcmd from unpacked folder. But for longer run I still suggest to use docker image as suggested by @Kunda1

Cheers!
Last edited by amrit3701 on Sat Sep 10, 2022 6:40 am, edited 1 time in total.
Amritpal Singh
Github, Like my work, sponsor me!
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Run 'freecad -c' from php throws error qt.qpa.xcb: could not connect to display

Post by Kunda1 »

amrit, nice to see you. One request: please try to limit the amount of text you're quoting (it makes the thread more readable). TIA
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
agustavo87
Posts: 10
Joined: Tue Jul 05, 2022 4:17 pm

Re: Run 'freecad -c' from php throws error qt.qpa.xcb: could not connect to display

Post by agustavo87 »

amrit3701 wrote: Fri Sep 09, 2022 6:08 pm To replicate issue on command line, login to www-data user (command: su -s /bin/bash www-data), and then run freecad.AppImage freecadcmd "print(2+2)”.
Effectively, that reproduces the error. But actually I think that www-data is the user of Apache, and currently I'm using the internal PHP server via Laravel's artisan serve command. I'm not sure if I'm right in this, but if I run whoami from a HTTP request sail is the ouptut.
amrit3701 wrote: Fri Sep 09, 2022 6:08 pm I would suggest to unpack AppImage, give all required permissions and then run freecadcmd from unpacked folder.
So I ran ./vendor/bin/freecad --appimage-extract and it creates a directory with the following permissions, user and group ownerships drwxr-xr-x 3 sail sail 4096 Sep 12 17:53 squashfs-root. So I change permissions with chmod -R 777 squashfs-root/. And the results are as follow
  • From the shell:
    sail@85be1f090757:/var/www/html$ ./squashfs-root/AppRun freecadcmd -c "print(2+2)"

    Code: Select all

    4
  • From the HTTP:
    whoami && ../squashfs-root/AppRun freecadcmd -c "print(2+2)" 2>&1

    Code: Select all

    sail Initialization of FreeCAD failed: Unknown runtime error occurred while initializing FreeCAD. Please contact the application's support team for more information.
    
  • From the HTTP:
    whoami && ../squashfs-root/AppRun python -c "print(2+2)" 2>&1

    Code: Select all

    sail 4
    
Thanks!
User avatar
adrianinsaval
Veteran
Posts: 5553
Joined: Thu Apr 05, 2018 5:15 pm

Re: Run 'freecad -c' from php throws error qt.qpa.xcb: could not connect to display

Post by adrianinsaval »

Use the --log-file argument to specify where to store the log file and attach the log please
agustavo87
Posts: 10
Joined: Tue Jul 05, 2022 4:17 pm

Re: Run 'freecad -c' from php throws error qt.qpa.xcb: could not connect to display

Post by agustavo87 »

adrianinsaval wrote: Tue Sep 27, 2022 2:13 pm Use the --log-file argument to specify where to store the log file and attach the log please
When the error occurs, there is no log file written. When it works the file is the attached:
Attachments
myfreecadlog.log
Log when freecad works in the conditions mentioned previously.
(7.18 KiB) Downloaded 22 times
Post Reply