ModuleNotFoundError: no module named XY

323 Views Asked by At

ModuleNotFoundError: no module named XY

XY is the cloned repository

The above error is a result of the import statement at the beginning of the training file.

I have cloned a repository from GitHub and installed it on my root directory. When I execute the train.py file I get the above error.

Please let me know if more details are needed for the above issue.

1

There are 1 best solutions below

0
Daniel On

When you try to import a package, Python will look through

  1. built-in modules
  2. directories in sys.path

If you import sys and print sys.path, you'll get a list of those directories. Note that '' corresponds to the current directory, which you can get with os.getcwd().

Most likely, your root directory is not on this path, and you are not launching Python from your root directory. You probably should not be putting random source folders in your root directory. You could:

  1. Try moving your package to a directory already on the path.
  2. Add another path for Python to search, such as by editing PYTHONPATH (format is specified in the docs). Looks like you're on a Unix system, so it would be directory pathnames separated by a colon.