Import InfluxDBClient fails in python code

Ok, I think I see the problem - hinted at by @Anaisdg’s post in the discussion that somehow got “forked” into the other thread.

Option 1: Legacy client
To use the legacy (Influx 1.x focused) client, you need to install with

pip3 install influxdb

to get this package: influxdb · PyPI, and then when you run Python you should be able to import it with

from influxdb import InfluxDBClient

as you’ve been attempting so far.

Option 2: New client
If you’d like to use the new (Influx 2.0 focused) client, you need to install with

pip3 install influxdb-client

to get this package: influxdb-client · PyPI, and then when you run Python you should be able to import it with

import influxdb_client

In short, I think what happened is that you’ve installed the new Python package, but are trying to import the legacy one (which isn’t installed). If you’re running an Influx 1.8 server (as I gather from your other thread), then you should be able to use either package. It’s mostly down to whether you’d like to write your queries using Flux - in which case use the new client - or InfluxQL - in which case you should use the legacy client. Flux is very powerful, but if you’re looking to do something reasonably simple then InfluxQL will probably be fine.

3 Likes