0

I have the following project structure:

enter image description here

The examples folder is where I will create notebooks, and the library well it's a library.

The setup.py looks like this:

from setuptools import setup, find_packages
from pathlib import Path

# version
here = Path(__file__).absolute().parent
version_data = {}
with open(here.joinpath("library", "__init__.py"), "r") as f:
    exec(f.read(), version_data)
version = version_data.get("__version__", "0.0") ## If not found, use 0.0

install_requires = [
    "numpy",
    "pandas",
    "scikit-learn",
    "matplotlib",
    "ipykernel",
    "jupyter",
    "pytest",
    "black",
]


setup(
    name="library",
    version=version,    
    install_requires=install_requires,
    package_dir={"library": "library"},
    python_requires=">=3.6, <3.11",
    packages=find_packages(where=".", exclude=["docs", "examples", "tests"])
)

In the folder library / datasets I have a file ledgerline.py

import pandas as pd    

class LedgerLine:
    """
    Ledger Line
    """

    def __init__(self):
        """Initialization.
        Args:
        """

    def getLedger(self):
        """Get all ledgar data.
        Returns:
        dataframe: Ledger Data.
        """
        ledgerDF = pd.read_csv("ledgerline.csv")
        return ledgerDF

    def getLedgerCredit(self):
        """Get all ledger credit data.
        Returns:
        dataframe: Ledger Credit Data.
        """
        return self.getLedger().query('debitcredit=="C"')

    def getLedgerDebit(self):
        """Get all ledger debit data.
        Returns:
        dataframe: Ledger Debit Data.
        """
        return self.getLedger().query('debitcredit=="D"')

And Inside library / models / LightGBM I have a file called Preprocess.py

import library.datasets.ledgerline as ledgerline


class PreProcess:
    """Preprocess data for LightGBM model.
    Examples:
       >>> import PreProcess
    """

    def __init__(self, credit=True):
        """Initialization.
        Args:
        credit= By default gets credit data
        """
        self.credit = credit

    def import_data(self):
        if self.credit:
            df = ledgerline.getLedgerCredit()
        else:
            df = ledgerline.getLedgerDebit()
        return df

    def convert_data_type(self):
        pass

    def handle_missing_values(self):
        pass

    def handle_outliers(self):
        pass

    def transform_data(self):
        pass

Now in Examples folder I have a model1.ipynb where the only thing I want to do is start using my own library:

import library.datasets as lib
ModuleNotFoundError: No module named 'library'

I executed

pip install -e .

and I got the following output

Installing collected packages: library
  Running setup.py develop for library
Successfully installed library-0.1.0

What am I missing?

gre_gor
  • 6,669
  • 9
  • 47
  • 52
Luis Valencia
  • 32,619
  • 93
  • 286
  • 506

0 Answers0