Reputation:
I am currently trying to run a sample code I code off of the internet.
While trying to run it using python2.7, I get the following ERROR :
# python2.7 example.py
Traceback (most recent call last):
File "example.py", line 9, in <module>
from http.server import HTTPServer
ImportError: No module named http.server
I tried to run the following :
# pip install http.server
Collecting http.server
Could not find a version that satisfies the requirement http.server (from versions: )
No matching distribution found for http.server
But when I use python3, it does not give me the ERROR. Rather gives the ERROR :
# python3 example.py
Traceback (most recent call last):
File "example.py", line 13, in <module>
from prometheus.client import Gauge
ImportError: No module named 'prometheus.client'
Im trying to install prometheus.client
using pip and pip3 but nothing.
# pip install prometheus.collectors
Collecting prometheus.collectors
Could not find a version that satisfies the requirement prometheus.collectors (from versions: )
No matching distribution found for prometheus.collectors
# pip3 install prometheus.collectors
Collecting prometheus.collectors
Could not find a version that satisfies the requirement prometheus.collectors (from versions: )
No matching distribution found for prometheus.collectors
How can I get the missing libraries ?
EDIT ::
In the below example I am using a very minimalist approach (again from github)
from prometheus_client import start_http_server, Summary
import random
import time
# Create a metric to track time spent and requests made.
REQUEST_TIME = Summary('request_processing_seconds', 'Time spent processing request')
# Decorate function with metric.
@REQUEST_TIME.time()
def process_request(t):
"""A dummy function that takes some time."""
time.sleep(t)
if __name__ == '__main__':
# Start up the server to expose the metrics.
start_http_server(8000)
# Generate some requests.
while True:
process_request(random.random())
Running the above code yields :
# python3.4 main.yaml
Traceback (most recent call last):
File "main.yaml", line 1, in <module>
from prometheus_client import start_http_server, Summary
ImportError: No module named 'prometheus_client'
Whereas I do have the library installed.
# pip3 install prometheus_client
Requirement already satisfied: prometheus_client in /usr/lib/python2.7/site-packages
Upvotes: 3
Views: 20695
Reputation: 216
I had already installed prometheus_client==0.21.0
, but faced same error.
Downgrading to prometheus_client==0.20.0
worked for me:
pip3 install prometheus_client==0.20.0
Upvotes: 0
Reputation: 401
sudo -H pip3 install prometheus_client
just worked for me
Found here https://github.com/b-harvest/terra_oracle_voter_deprecated/issues/17
Upvotes: 0
Reputation: 384
I faced the exact same problem. I installed pip3
using python3 -m pip install --upgrade pip
. After that ran pip3 install prometheus_client
. After this, the issue got fixed.
Upvotes: 0
Reputation: 2751
I'm running on ubuntu 18.10 and i got the same issue, and i have python2 install already. I was able to solved it by installing python3 and python3-pip like below.
sudo apt install python3
sudo apt install python3-pip
pip3 install prometheus_client
May be helpful to somebody!
Upvotes: 4
Reputation: 1307
http.server
is a module in Python 3.
See the note for SimpleHTTPServer
in Python 2:
Note The
SimpleHTTPServer
module has been merged intohttp.server
in Python 3. The2to3
tool will automatically adapt imports when converting your sources to Python 3.
For prometheus.client
, you want pip install prometheus_client
. See https://github.com/prometheus/client_python
README.md from the repository you linked states:
Deprecated, use: https://github.com/prometheus/client_python
Upvotes: 1