吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 960|回复: 3
收起左侧

[求助] [已解决] python3 setup.py install 安装的项目如何增加配置文件?

[复制链接]
wajika 发表于 2022-1-11 14:51
本帖最后由 wajika 于 2022-1-12 14:39 编辑

我下载了某个开源项目,它可以用 python setup.py install   方式安装,我在这个项目代码里引用了一个自定义的modules,其实就是放一个目录(elastalert_modules)到这个项目里,在ubuntu 20.04 里运行时出现下面的错误提示

[Python] 纯文本查看 复制代码
elastalert.sh 
--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/util.py", line 28, in get_module
    base_module = __import__(module_path, globals(), locals(), [module_class])
ModuleNotFoundError: No module named 'elastalert_modules'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/loaders.py", line 516, in load_alerts
    alert_field = [create_alert(a, b) for a, b in alert_field]
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/loaders.py", line 516, in <listcomp>
    alert_field = [create_alert(a, b) for a, b in alert_field]
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/loaders.py", line 500, in create_alert
    alert_class = self.alerts_mapping.get(alert) or get_module(alert)
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/util.py", line 31, in get_module
    raise EAException("Could not import module %s: %s" % (module_name, e)).with_traceback(sys.exc_info()[2])
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/util.py", line 28, in get_module
    base_module = __import__(module_path, globals(), locals(), [module_class])
elastalert.util.EAException: Could not import module elastalert_modules.wechat_qiye_alert.WeChatAlerter: No module named 'elastalert_modules'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/loaders.py", line 156, in load
    rule = self.load_configuration(rule_file, conf, args)
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/loaders.py", line 219, in load_configuration
    self.load_modules(rule, args)
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/loaders.py", line 483, in load_modules
    rule['alert'] = self.load_alerts(rule, alert_field=rule['alert'])
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/loaders.py", line 519, in load_alerts
    raise EAException('Error initiating alert %s: %s' % (rule['alert'], e)).with_traceback(sys.exc_info()[2])
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/loaders.py", line 516, in load_alerts
    alert_field = [create_alert(a, b) for a, b in alert_field]
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/loaders.py", line 516, in <listcomp>
    alert_field = [create_alert(a, b) for a, b in alert_field]
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/loaders.py", line 500, in create_alert
    alert_class = self.alerts_mapping.get(alert) or get_module(alert)
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/util.py", line 31, in get_module
    raise EAException("Could not import module %s: %s" % (module_name, e)).with_traceback(sys.exc_info()[2])
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/util.py", line 28, in get_module
    base_module = __import__(module_path, globals(), locals(), [module_class])
elastalert.util.EAException: Error initiating alert ['elastalert_modules.wechat_qiye_alert.WeChatAlerter']: Could not import module elastalert_modules.wechat_qiye_alert.WeChatAlerter: No module named 'elastalert_modules'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/elastalert", line 11, in <module>
    load_entry_point('elastalert2==2.2.1', 'console_scripts', 'elastalert')()
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/elastalert.py", line 2151, in main
    client = ElastAlerter(args)
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/elastalert.py", line 132, in __init__
    self.rules = self.rules_loader.load(self.conf, self.args)
  File "/usr/local/lib/python3.8/dist-packages/elastalert2-2.2.1-py3.8.egg/elastalert/loaders.py", line 164, in load
    raise EAException('Error loading file %s: %s' % (rule_file, e))
elastalert.util.EAException: Error loading file /home/wajika/elastalert2/es_rules/bpm.yaml: Error initiating alert ['elastalert_modules.wechat_qiye_alert.WeChatAlerter']: Could not import module elastalert_modules.wechat_qiye_alert.WeChatAlerter: No module named 'elastalert_modules'


如果我进入包含elastalert_modules目录的位置,在运行elastalert.sh ,那么就不会提示  No module named 'elastalert_modules',这个问题怎么理解? 我需要创建一个PYTHONPATH?

ubuntu里用自带的python的话 怎么将elastalert_modules目录放到 setup.py install 安装的位置?


发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

52小柯柯 发表于 2022-1-11 16:26
os.path.append("这个模块的路径")
yjn866y 发表于 2022-1-11 19:30
 楼主| wajika 发表于 2022-1-12 14:39
问题解决了,因为在ubuntu中 普通用户和root 所安装的python 包位置不一样
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 16:40

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表