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.
Thanks again for your input. Apologise for confusing by using more than one thread, perhaps a Moderator could sort that for me. I will post a ‘moved to here’ comment to the other one.
I am using influxdb 1.8 and it is active as confirmed by my command line entries, influx
Connected to http://localhost:8086 version 1.8.0
InfluxDB shell version: 1.8.0
and sudo systemctl status influxdb
● influxdb.service - InfluxDB is an open-source, distributed, time series databa
Loaded: loaded (/lib/systemd/system/influxdb.service; enabled; vendor preset:
Active: active (running) since Sat 2020-05-09 19:38:03 BST; 2 days ago
Docs: InfluxDB OSS v2 Documentation
Main PID: 23411 (influxd)
Memory: 76.4M
CGroup: /system.slice/influxdb.service
└─23411 /usr/bin/influxd -config /etc/influxdb/influxdb.conf
All this was fairly straightforward and trouble free. It is when I add the:
import influxdb_client
line into my code I get an error.
sudo python3 app_280.py
Traceback (most recent call last):
File “app_280.py”, line 27, in
from influxdb import InfluxDBClient #unremark to test
ModuleNotFoundError: No module named ‘influxdb’
Hope this helps clarify.
Two points:
Can you clarify whether you’re trying to use the legacy or the new client? In your last post you say that you get an error when you add import influxdb_client
, but the actual error you quote is with respect to the influxdb
module not being found (not the influxdb_client
).
You’re running your Python code with sudo, i.e. as the root
user. Is there a reason for doing that? It’s likely to complicate your package installation situation, and could be the reason for packages not being found - e.g. if you ran pip3 install ...
to install packages as your regular user, but then run sudo python ...
, the installed packages won’t be found.
Thanks for continuing with this for me. Re-reading my last post I did not make it clear, I blame the Grandchildren, continuously interrupting me, the joys of lockdown in a family home!
Taking point 2. first. My app_280.py is a modified version of one written by someone else which acts a web server to display data collected to a webpage with PIs IP address, he told me it needed sudo because of this, I just followed his advice. Being a novice I might have used it when I shouldn’t have in some subsequent steps with INfluxdb. Presumably I can check file ownerships and alter them, or would it be better just to do it again?
Point 1. It was the legacy version of influxdb_client I downloaded, running pip3 install… again I get:
pip3 install influx-client
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: Simple index, piwheels - Simple index
Requirement already satisfied: influx-client in /usr/local/lib/python3.7/dist-packages (1.9.0)
Requirement already satisfied: simplejson in /usr/lib/python3/dist-packages (from influx-client) (3.16.0)
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (from influx-client) (2.21.0)
Requirement already satisfied: pytool in /usr/local/lib/python3.7/dist-packages (from influx-client) (3.15.0)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from pytool->influx-client) (1.12.0)
which I have seen several times now.
The influxdb-client-python github source says to follow the pip3 install… command with
import influxdb_client
This errors with bash:
import command not found
Ok, thanks for the explanation.
Since you’re running python3 with sudo, you also need to run pip3 with sudo - in order to install the package for the root user. Try
sudo pip3 install influx-client
Finally, import influxdb_client
is the command that’s run in your Python script (as I think you realize) rather than from your bash prompt.
Thanks.
I ran the sudo pip3 line and it came back with already satisfied lines, as before
Unremarked my import line in my code and it came back with this error.
sudo python3 app_280.py
Traceback (most recent call last):
File “app_280.py”, line 27, in
from influxdb import InfluxDBClient #unremark to test
ModuleNotFoundError: No module named ‘influxdb’
Could this be something to do with my apps scope? Not sure if this is the correct terminology! My app is not aware of all the recent installs.
It looks like there is still some confusion regarding the legacy vs new version of the package you’re installing and respectively running. I suspect what you’ve done is install the new version (which is what you were importing in your code above), but it now looks like you’re trying to import the legacy version (influxdb
), which is causing an error.
Have you tried running the following?
sudo pip3 install influxdb
Thanks again, must be hard trying sort this at a distance.
I don’t think I had run that so I did and got a list of already satisfied lines, a couple of download lines with Successfully installed influxdb-5.3.0 msgpack-0.6.1 as the final line.
I then ran my code from the command line and no error, brilliant !
So which element was legacy and how did I do it, was it using pip instead of pip3?
Now I will have to learn how to get my code to populate the database, then onto Grafana!!
Good job I have some time. Thanks so much.
Hi, i am having a python-Flask based app (module name = logging_module.py
, app name: webLogger
) that is suppose to write data into my influx db.
I am using Gunicorn WSGI server. When i initialize the app with command:
gunicorn -w 1 -b :8000 logging_module:webLogger
i get error: no module named ‘influxdb_client’
Although , i only have python3.9 installed and i can see influxdb_client v1.36.1
when i run “pip3 list
” command.
when i try to import to the module manually:
import influxdb_client
The it works without error.
Any help on this?