Why am I gettitng ModuleNotFoundError when importing file in directory?

85 Views Asked by At

I have opened a remote github repository in vs code that contains a project for uni. The structure of the project is as follows:

walking_panda
└──__init__.py
└── cli.py
└── panda.py
walking_panda.py

walking_panda.py contains the following code:

#!/usr/bin/env python

from walking_panda.cli import cli

if __name__ == '__main__':
    cli()

When executing the file it returns this error:

ModuleNotFoundError: No module named 'walking_panda'

Is there something wrong with my from statement, or is it to do with the fact that the files are in a remote repository and not actually stored on my computer? I am also running using the Jupyter Interactive extension on vs code if that makes any difference. Also using linux mint.

1

There are 1 best solutions below

0
On

Chances are that the file walking_panda.py is executed from another directory than the one it is located. If you can modify it, try to add:

import os
print(os.getcwd())
print(os.listdir())

That should show from where python is called and if there is the module walking_panda in this same place. For info, the current working directory (where python is executed from) is inserted at index 0 of the sys.path, which lists all the directories where modules can be imported from.