When develop a web project based on Django using PyCharm, I try to import from other python modules. However, it got the “ImportError: No module named XXX” error.

I searched for some solutions, but not every one method works. The following is the method that works for me.

How to fix “ImportError: No module named XXX in PyCharm”?

The version of PyCharm is PyCharm 2019.3.3 (Professional Edition) for Mac, I think the solution also works for other versions.

Solution:

Click the menu PyCharm item on the left-top, then click Preferences item to open the config panel.

Then Project -> Project Structure. Now, you should select your python code package folder on the right project structure, then click the Sources icon to add the package folder use as Source Folders.

Then click Apply and OK

It’s done. Now you will see the “ImportError: No module named XXX” error go away in your PyCharm.