简体   繁体   English

无法在Python中导入RRDtool

[英]Unable to import RRDtool in Python

I am trying to import RRDtool into Python as I want to access an RRD database using Python, but when I am trying to import rrdtool I am getting the following error. 我想将RRDtool导入Python,因为我想使用Python访问RRD数据库,但是当我尝试import rrdtool时,出现以下错误。

Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append('/opt/rrdtool-1.4.5/bin')
>>> import rrdtool
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named rrdtool

My RRDtool is located in /opt/rrdtool-1.4.5/bin . 我的RRDtool位于/opt/rrdtool-1.4.5/bin

Well, the problem is solved just by executing the following command. 好了,仅通过执行以下命令即可解决该问题。

sudo apt-get install python-rrd 须藤apt-get install python-rrd

It is unlikely that Python modules are located inside a 'bin' folder. Python模块不太可能位于“ bin”文件夹中。 And importing files from some configured path requires that the referred path is a proper Python package. 从某些配置的路径导入文件要求引用的路径是正确的Python包。 It means it must contain an __init__.py file. 这意味着它必须包含__init__.py文件。

您可能需要py-rrdtool ,可以直接从网站或软件包管理器获取。

You could use the RRDtool documentation for inspiration ( man rrdpyton ). 您可以使用RRDtool文档进行启发( man rrdpyton )。 Something along the lines of 遵循以下原则

import sys
sys.path.append('/path/to/rrdtool/lib/python2.6/site-packages/')
import rrdtool

should do the trick. 应该可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM