Skip to content

Checking your reading list…

Retry verification

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

How to Fix Python ImportError: No module named XXX in PyCharm Projects

How to Fix Python ImportError: No module named XXX in PyCharm Projects

This guide explains why Python projects in PyCharm may raise 'ImportError: No module named XXX' despite file navigation working, and provides step‑by‑step fixes by adding the project root to the import path and correctly setting the working directory.

Problem

When running a Python project in PyCharm, you may encounter the error ImportError: No module named XXX . The IDE can navigate to the file, but execution fails because the module cannot be found.

Solution

1. At the top of the affected .py file, add the project’s root directory to the import path. For example:

import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

2. Verify and adjust the Working Directory of the run configuration. Ensure it points to the correct project folder.

3. Double‑check that PyCharm’s automatically generated file references are accurate; sometimes they may point to the wrong location.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

Report an issue with this article
PyCharmimporterrormodule-not-found

Reader feedback

Was this useful?

Useful0

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion