


How to solve the error when opening terminal using python under linux
When using python to open the terminal under linux, an error occurs
Scenario 1: Execute automated tasks on jenkins, use the jenkins user (with sudo permissions) when executing test tasks, and the test script is in linux When executing (background), an error occurs when the following code is executed:
os.system(f"/usr/bin/konsole -e {cmd_orin2_10s}")
Scenario 2: There is no problem with the test script being executed locally. When executing locally, the root user can be used and the command window can be opened normally
Error log:
17:44:03 qt.qpa.xcb: could not connect to display 17:44:03 qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found. 17:44:03 This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. 17:44:03 17:44:03 Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.
Solution:
It can be compared from scenario 1 and scenario 2, it should be caused by environment variables cause. To find the problem from the environment variables and the displayed window, you can find export DISPLAY=":0.0"
Supplement: pycharm runs without problems but the terminal (terminal) runs various modules. Problem
Problem Description
Many times you are used to using pycharm and have everything done, but you ignore many path problems. Occasionally, you need to interact with other environments and platforms. For example, if you write a C# program to call python, it is equivalent to passing parameters to the terminal to start. At this time, various No module problems will be displayed. The reason is because the external environment calls the python interface. , you have to look for each module in your program, but if these modules have not been added to the environment variables, they will not be found. Therefore, it is recommended to use the following statement at the front of each py file used
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../')
This operation can add the entire upper-level directory of the current file to the environment variable, so that all files under the upper-level directory can be easily called
If you have many directory levels and the current directory is in a deep location, then you can slightly change this command to include all the files and directories you want to use, such as Yes
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../../')
Of course if you just want to call all directories under the current folder, then you can use
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + './')
The above is the detailed content of How to solve the error when opening terminal using python under linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.

VS Code To switch Chinese mode: Open the settings interface (Windows/Linux: Ctrl, macOS: Cmd,) Search for "Editor: Language" settings Select "Chinese" in the drop-down menu Save settings and restart VS Code

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

The main differences between VS Code and PyCharm are: 1. Extensibility: VS Code is highly scalable and has a rich plug-in market, while PyCharm has wider functions by default; 2. Price: VS Code is free and open source, and PyCharm is paid for professional version; 3. User interface: VS Code is modern and friendly, and PyCharm is more complex; 4. Code navigation: VS Code is suitable for small projects, and PyCharm is more suitable for large projects; 5. Debugging: VS Code is basic, and PyCharm is more powerful; 6. Code refactoring: VS Code is basic, and PyCharm is richer; 7. Code

VS Code supports Chinese settings, which can be completed by following the steps: Open the settings panel and search for "locale". Set "locale.language" to "zh-CN" (Simplified Chinese) or "zh-TW" (Traditional Chinese). Save settings and restart VS Code. The settings menu, toolbar, code prompts, and documents will be displayed in Chinese. Other language settings can also be customized, such as file tag format, entry description, and diagnostic process language.

Golang is more suitable for high concurrency tasks, while Python has more advantages in flexibility. 1.Golang efficiently handles concurrency through goroutine and channel. 2. Python relies on threading and asyncio, which is affected by GIL, but provides multiple concurrency methods. The choice should be based on specific needs.
