Sorry for the confusion. So here is the module I am importing.
# Main DB
import os
import pandas as pd
from influxdb_client import InfluxDBClient, Point, Dialect
from influxdb_client.client.write_api import SYNCHRONOUS
# Local module within the same dir. This works when I run this module by itself
from query_builder import QueryBuilder
class DB:
def _make_client(self):
# Establish client
client = InfluxDBClient(url = url, token = token, org = org)
return client
def run_query(self, param, tank, time_range, time_unit, bucket = bucket):
# Build out value and validity objects
# Testing params=
value_query_obj = QueryBuilder(param, tank, time_range, time_unit, bucket)
# Set up client to run the query
value_query = value_query_obj.query_builder()
client = self._make_client()
# Run queries
query_api = client.query_api()
value_records = query_api.query_stream(query = value_query)
# Close out client connection
client.__del__()
# Create 2D array and use that to populate dataframe
record_arr = []
for records in value_records:
record_arr.append([records["_time"], records["_value_vals"], records["_value_valid"]])
# Create dataframe
df = pd.DataFrame(record_arr, columns = ['timestamp', 'reading', 'validity'])
return df
Here is the module that I am trying to import this into:
import pandas as pd
import sys
# This does seem to import the module but causes other errors
sys.path.insert(0, 'C:/Dev/UpwardFarms/')
from data.db import *
databass_obj = db.DB()
#Testing data imports. Come back to this when you figure out how to do module imports
print_df = databass_obj.run_query("Temperature", "Tank1", "10", "m")
print(print_df)
This seems to work but I get the following error when I try to run the anomaly file:
Traceback (most recent call last):
File "anomaly.py", line 4, in <module>
from data.db import *
File "C:/Dev/UpwardFarms\data\db.py", line 8, in <module>
from query_builder import QueryBuilder
ModuleNotFoundError: No module named 'query_builder'
This is the project directory:
root/
-__init__.py
-data/
-__init__.py
-query_builder.py
-db.py
-anomaly/
-anomaly.py
-__init__.py
I would prefer to use absolute imports rather than setting the sys path manually. Especially since I seem to be getting errors otherwise.