pythonimportpycharmmodulenotfounderror

ModuleNotFoundError in Pycharm while importing from existing folder


I'm running a Python project in Pycharm structured as shown in the image and I'm trying to perform the following import in embedder_cmd.py : from Neural_PM.clustering.clustering_experiment import run_clustering

I currently get the following error:
ModuleNotFoundError: No module named 'Neural_PM'

I've tried the solutions proposed in the previous answers but nothing seems to work for me.

Printing os.environ['PYTHONPATH'] currently shows my project path: C:\Users\Mark\PycharmProjects\pythonProject4

Project structure


Solution

  • Try this from ..clustering.clustering_experiment import run_clustering. The two dots before clustering is to get out runners folder as your import statement is in embedder_cmd.py.
    If that doesn't work and you get the "no known parent package" error, try without dots, like this from clustering.clustering_experiment import run_clustering and run py -m <path to embedder_cmd.py> at the top level of your project in terminal.
    Something like this:
    test code
    Now look the result:
    test result