Search code examples
pythonmoduledirectoryfilepath

path directory not being recognised by my code


enter image description hereMy code will not recognise my path directory or allow me to import other modules within the same root directory. Here below is my code:

import streamlit as st
from sentimentanalysis import save_audio

and here is the error I am being returned with: No module named 'sentimentanalysis'

I have tried:

  • numerous things such as adding init.py.

  • Checked the codes directory using import sys;print(sys.path[0]) which returns the directory I expect.

The directory path is:

sentimentanalysis(root directory)

  • Save_audio
    • save_audio
  • app.py
    • app.y
  • Configure.py
    • configure.py

Solution

  • Try to import like this :

    from sentimentanalysis.Save_audio import save_audio
    

    Module structure mean directory groupping.
    So you have no global view about what inside package.
    Also it is important to have __init__.py inside module dir.
    Otherwise relative import only option