我目前正试图在互联网上运行一个样本代码 i代码。
在尝试使用python2.7运行它时,我得到以下错误:
# 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
我试着运行以下命令:
# 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
但是当我使用python3时,它不会给出错误。而是给出了错误:
# 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'
我试着用pip和pip3安装prometheus.client
,但什么也没有。
# 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
我怎么才能得到丢失的图书馆?
编辑::
在下面的例子中,我使用了一种非常简约的方法(同样来自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())
运行上述代码将产生以下结果:
# 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'
而我确实安装了图书馆。
# pip3 install prometheus_client
Requirement already satisfied: prometheus_client in /usr/lib/python2.7/site-packages
发布于 2019-03-19 21:16:37
我在ubuntu18.10上运行,我也遇到了同样的问题,而且我已经安装了python2。我可以通过安装python3和python3-pip来解决这个问题,如下所示。
sudo apt install python3
sudo apt install python3-pip
pip3 install prometheus_client
可能对某人有帮助!
发布于 2017-12-22 20:49:03
http.server
是Python3中的一个模块。
请参阅Python2中的SimpleHTTPServer
注释:
注意,
SimpleHTTPServer
模块已经合并到Python3中的http.server
中。2to3
工具在将源转换为Python3时将自动调整导入。
对于prometheus.client
,你想要pip install prometheus_client
。请参阅python
不推荐,使用:python
发布于 2020-01-02 21:28:21
我也面临着同样的问题。我使用pip3
安装了python3 -m pip install --upgrade pip
。之后运行了pip3 install prometheus_client
。在这之后,问题就解决了。
https://stackoverflow.com/questions/47947176
复制相似问题