'IDE does not recognise my own package from pypi

I am attempting to use my own package that I have uploaded to Pypi, similar to this user done in this post but adding the init file at my root folder does not seem to work.

For ref this is my package link with my package called heart-disease-classification-model. This is the github repo

I have installed the package with the correct version using pip in my virtualenv but when I run the command:uvicorn api:app --reload

The error points to this line: from heart-disease-classification-model.predict import make_prediction_inputs_api which leads me to suspect that the build is not done properly.

My api file:

import pandas as pd
from fastapi import FastAPI, HTTPException
from fastapi.encoders import jsonable_encoder
from config.settings import API_VERSION, APP_NAME
from heart-disease-classification-model import make_prediction_inputs_api
import schema
from config.settings import API_VERSION

# I initialise these as static first
MODEL_NAME = 'Random Forest'
MODEL_VERSION = '0.0.2'

app = FastAPI()

# root, display a rudimentary homepage
@app.get('/')
def homepage():
    return {'message':f'Welcome to {APP_NAME}'}

@app.get("/health", response_model=schema.health, status_code=200)
def health_of_api():

    health =schema.health(apiVerson =API_VERSION, modelVersion= MODEL_VERSION,modelName= MODEL_NAME )

    return health.dict()

@app.post('/predict', response_model=schema.PredictionResults, status_code=200)
async def predict_value(input_data):
    input_df = pd.DataFrame(jsonable_encoder(input_data.inputs))

    results = make_prediction_inputs_api(input_data=input_df)

    if results['errors'] is not None:
        raise HTTPException(status_code=400, detail= json.loads(results["errors"]))

    return results

Any suggestions?

Thanks



Solution 1:[1]

I found that the issue was due to how I named the root folder. In this case my root folder was named 'src' instead of my package name so I had to simply import src, beginner's mistake.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Randy Chng