Home / Guides / Fix

PyQt Troubleshooting: Fix Common Errors

Solve the most common PyQt errors — ModuleNotFoundError, the xcb platform plugin error, pip build failures, blank windows and Designer problems.

FIX

PyQt Troubleshooting: Fix Common Errors

Hit an error installing or running PyQt? This guide lists the problems people meet most, explains why each happens, and gives the exact fix so you can get back to building.

No module named PyQt6

This is the most common error by far. It means pip installed PyQt into a different Python than the one running your script. The fix is to use the same Python for both:

terminal
python -m pip install PyQt6

Running pip through python -m pip guarantees they match. If you use a virtual environment, make sure it is active first.

The xcb plugin error

On Linux you may see "could not load the Qt platform plugin xcb". Qt needs some system libraries that are not always present. Install them:

terminal
sudo apt install libxcb-cursor0 libxcb-xinerama0

After that, run your app again. On other distros the package names differ slightly, but the idea is the same.

pip build or wheel errors

PyQt6 ships ready-built wheels, so you should not need to compile anything. A build error usually means pip is old and cannot find the wheel. Upgrade it, then reinstall:

terminal
python -m pip install --upgrade pip
pip install PyQt6

Blank or closing window

If your window flashes and vanishes, the app object was likely cleaned up too early. Keep a reference to QApplication, and call app.exec() as the last line. That call starts the loop that keeps the window open.

Run your script from a terminal, not by double-clicking. That way you can read the error message instead of watching the window disappear.

Designer will not open

If the designer command is missing, install the tools package:

terminal
pip install pyqt6-tools
pyqt6-tools designer

On some setups Designer ships with a full Qt install instead. Our Qt Designer guide covers both paths.

Mixing versions

Importing both PyQt5 and PyQt6 in one program causes crashes and strange import errors. Pick one major version per project and stick with it. If you must run both, use separate virtual environments.

High-DPI and scaling

On high-resolution screens, an app can look tiny or blurry if scaling is off. Qt 6 handles high-DPI far better than older versions, so moving to PyQt6 already solves many cases. If text still looks small, check your system display scaling first.

Avoid hard-coding pixel sizes everywhere. Let layouts and size policies do the work, and your interface will adapt to different screens with far less fuss.

Reading logs and messages

When something breaks, the terminal is your friend. Run the app from a command line so you can read Qt's messages. They often name the exact missing plugin, file or module, which turns guesswork into a quick fix.

Add your own print() lines inside slots to see whether they run and what values arrive. Simple as it sounds, this clears up most "why isn't this working" moments fast.

The clean-slate fix

When nothing else works, reset the environment. Delete the virtual environment folder, create a fresh one, upgrade pip, and reinstall PyQt6. A surprising number of stubborn problems vanish with a clean install.

Because everything lived inside that folder, the reset is safe and quick. It is often faster to rebuild than to hunt for a tangled cause.

Preventing problems early

The best fix is the problem you never have. A few habits prevent most PyQt trouble. Always work in a virtual environment, so installs stay clean. Keep pip up to date, so it fetches ready-built wheels instead of trying to compile.

Use python -m pip for every install, which ties pip to the Python you run and sidesteps the most common error of all. And stick to one PyQt version per project, since mixing PyQt5 and PyQt6 causes confusing crashes.

These habits cost nothing and save hours. Build them in from the start and your projects will run smoothly far more often.

Asking for help the smart way

Sometimes you still get stuck, and there is no shame in asking. You will get a faster answer if you share the right details. Include your operating system, your Python version, and your PyQt version.

Paste the full error message, not just a summary, and the few lines of code that trigger it. Say what you expected to happen and what actually happened. This turns a vague "it does not work" into a problem others can actually solve.

Often, writing the question clearly reveals the answer by itself. Explaining the problem step by step is a debugging technique in its own right.

Key takeaways

Most PyQt errors come from a short list of causes: pip installed into the wrong Python, missing system libraries on Linux, an out-of-date pip, a lost application reference, or two PyQt versions mixed in one program. Each has a quick, known fix.

Prevent the common ones with good habits. Work in a virtual environment, keep pip current, install with python -m pip, and stick to one PyQt version per project. These cost nothing and stop most problems before they start.

When you do get stuck, run from a terminal so you can read Qt's messages, and reset the environment if all else fails. And if you ask for help, share your OS, versions, the full error and the code — that turns a vague problem into a solvable one.

FAQs

Why does pip install the wrong place?

You may have several Python versions. Use python -m pip to tie pip to the Python you run.

My app works in the editor but not as an EXE. Why?

A data file was probably not bundled. See the packaging guide and the --add-data flag.

How do I read Qt error messages?

Run from a terminal. Qt prints the reason there, often naming the exact missing piece.

Is it safe to reinstall PyQt?

Yes. Reinstalling is a common, harmless fix. A fresh virtual environment is even cleaner.

Conclusion

Most PyQt errors come from a handful of causes: the wrong Python, missing system libraries, an old pip, or a lost app reference. Each has a quick fix. Work down this list and you will clear almost anything. Still stuck? Start fresh with our install guide in a clean virtual environment.

Ready to start? Download PyQt or run pip install PyQt6.