I had a Python script writing to my InfluxDB bucket and up until last week it was working fine. Then suddenly it stopped working and returning the error:
from influxdb_client import WritePrecision, InfluxDBClient, Point ModuleNotFoundError: No module named 'influxdb_client'
I have looked online, I have tried running
pip install influxdb
pip3 install influxdb,
pip3 install influxdb-client
and
pip install influxdb-client
I've reinstalled Python and pandas, I've tried
from influxdb import InfluxDBClient
instead of the code that is recommended from the InfluxDb page. I've tried it all in a different computer with a brand new installation of Windows and everything. I've tried it on Windows 10 and 11.
I've no idea what to try next and the very few explanations I have found are to try one of the above. The weird thing is that, it had been working and I did not change anything in the computer since. Not one thing.
I have Windows 11 (I've tried it on Windows 10 too but it did not work either), Python 3.11 and my code is below:
from datetime import datetime
from influxdb_client import WritePrecision, InfluxDBClient, Point
from influxdb_client.client.write_api import SYNCHRONOUS
def enviarDados(value):
url = 'http://localhost:8086'
token = 'my-token'
org = 'my-org'
bucket = 'my-bucket'
with InfluxDBClient(url=url, token=token, org=org) as client:
p = Point("my-measure").tag("sensor_id", "01").field("1n", value).time(datetime.utcnow(), WritePrecision.NS)
with client.write_api(write_options=SYNCHRONOUS) as write_api:
write_api.write(bucket=bucket, record=p)
for i in range(36000):
enviarDados(i)
As you can see I was just trying to populate with some dummy data to test the speed of recoding on a local installation of a Windows computer. It's important in our decision if we can use Influx for our sensor to find out exactly what's the minimum time between measures that it can record in a local installation and for it to be on a Windows computer as that is what is going to be used. But I haven't been able to test. Even though I used the same code I had been using before, just changed my loop. Anyway, it is not even getting to the loop since it returns an error in the second line as not having found influxdb_client.
If anyone had this problem and was able to fix it, let me know please.
Thanks!
I was expecting to be able to write to the Database, and I tried reinstalling inlufxdb, influxdb-client, Python, Windows, pretty much everything. I also tried importing from influxdb instead of influxdb_client, it just gives me the same error of module not found except for influxdb instead of influxdb_client.
It is recognizing other modules. It had no problem with datetime and random when I tried, even in this code, and my own modules. It's just the influxdb one it can't find.
As per the InfluxDB Python GitHub(which is also now archived and not being developed), you seem to be installing the python client for InfluxDB V1.x. Since you are using InfluxDB V2, try using pip install 'influxdb-client[ciso]'
or pip install 'influxdb-client[async]'
as per your requirements. This information can be found on the newer GitHub repo for InfluxDB V2.x.