python - ModuleNotFoundError: No module named 'LibraryExplorer' - Stack Overflow

admin2025-04-15  0

I am a newbie on python and cannot figure out how to solve this error.

This is the structure of my project:

and this is part of my code inside explorer.py

class Explorer:
    def __init__(self, library_path: str):
        self.library_path = library_path
        db_path = os.path.join(library_path, "library.json")

        # TinyDB will automatically create the file if it doesn't exist
        # or open it if it does exist
        self.db = TinyDB(db_path)

    def get_all_books(self) -> List[Book]:
        books = []

        results = self.db.all()

        for book_data in results:
            book = Book(book_data['author'], book_data['title'])
            book.set_filename(os.path.basename(book_data['path']))
            book.tags = book_data['tags']
            books.append(book)

        return books

in main.py try using the code but I got this error

Traceback (most recent call last): File "C:\Users\salva\OneDrive\Documents\Developing\ScriptLibraryManager\scripts\main.py", line 6, in from LibraryExplorer.explorer import Explorer ModuleNotFoundError: No module named 'LibraryExplorer'

just on

from LibraryExplorer.explorer import Explorer
from LibraryExplorer.book import Book

With print(f"Looking on {sys.path}") on main.py I getting this result

Looking on ['C:\\Users\\salva\\OneDrive\\Documents\\Developing\\ScriptLibraryManager', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0\\python313.zip', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundatio
n.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0\\DLLs', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0\\Lib', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0', 'C:\\Users\\salva\\OneDrive\\Documents\\Developing\\ScriptLibraryManager\\.venv', 'C:\\Users\\salva\\OneDrive\\Documents\\Developing\\ScriptLibraryManager\\.venv\\Lib\\site-packages']

and if I try to execute like this

python scripts/main.py

I get this

python scripts/main.py Traceback (most recent call last): File "C:\Users\salva\OneDrive\Documents\Developing\ScriptLibraryManager\scripts\main.py", line 9, in from LibraryExplorer.explorer import Explorer ModuleNotFoundError: No module named 'LibraryExplorer'

I am a newbie on python and cannot figure out how to solve this error.

This is the structure of my project:

and this is part of my code inside explorer.py

class Explorer:
    def __init__(self, library_path: str):
        self.library_path = library_path
        db_path = os.path.join(library_path, "library.json")

        # TinyDB will automatically create the file if it doesn't exist
        # or open it if it does exist
        self.db = TinyDB(db_path)

    def get_all_books(self) -> List[Book]:
        books = []

        results = self.db.all()

        for book_data in results:
            book = Book(book_data['author'], book_data['title'])
            book.set_filename(os.path.basename(book_data['path']))
            book.tags = book_data['tags']
            books.append(book)

        return books

in main.py try using the code but I got this error

Traceback (most recent call last): File "C:\Users\salva\OneDrive\Documents\Developing\ScriptLibraryManager\scripts\main.py", line 6, in from LibraryExplorer.explorer import Explorer ModuleNotFoundError: No module named 'LibraryExplorer'

just on

from LibraryExplorer.explorer import Explorer
from LibraryExplorer.book import Book

With print(f"Looking on {sys.path}") on main.py I getting this result

Looking on ['C:\\Users\\salva\\OneDrive\\Documents\\Developing\\ScriptLibraryManager', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0\\python313.zip', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundatio
n.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0\\DLLs', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0\\Lib', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0', 'C:\\Users\\salva\\OneDrive\\Documents\\Developing\\ScriptLibraryManager\\.venv', 'C:\\Users\\salva\\OneDrive\\Documents\\Developing\\ScriptLibraryManager\\.venv\\Lib\\site-packages']

and if I try to execute like this

python scripts/main.py

I get this

python scripts/main.py Traceback (most recent call last): File "C:\Users\salva\OneDrive\Documents\Developing\ScriptLibraryManager\scripts\main.py", line 9, in from LibraryExplorer.explorer import Explorer ModuleNotFoundError: No module named 'LibraryExplorer'

Share Improve this question edited Mar 13 at 19:28 Salvatore Di Fazio asked Mar 13 at 17:48 Salvatore Di FazioSalvatore Di Fazio 7152 gold badges7 silver badges27 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You probably need to fiddle with the python path; running from the ScriptLibraryManager folder, I believe this might work:

python -m scripts.main

Running the script directly with:

python scripts/main.py

probably won't work because the python path won't include the current dir. To figure out which folders your python implementation is searching for modules, do something like:

import sys

print(sys.path)
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744687046a261201.html

最新回复(0)