zoukankan      html  css  js  c++  java
  • Jenkins运行在Linux中,报No module namedxxxx(找不到包),如何解决

    Jenkins运行在Linux中,报No module namedxxxx(找不到包),如何解决

    1.在job的配置页面中的Execute shell中,需指明Python包的地址

    export PYTHONPATH=$PYTHONPATH:xxxxx/Lib/site-packages
    export PYTHONPATH=$PYTHONPATH:jenkis中的任务地址
    export PYTHONPATH=$PYTHONPATH:要执行的代码的上级目录
    cd 要执行的代码的上级目录
    chmod 777 要执行的代码
    sudo python3 要执行的代码

    2.在Python代码中,也要加路径

    import sys
    import os
    curPath = os.path.abspath(os.path.dirname(__file__)) #获取当前绝对路径
    filePath = os.path.split(curPath)[0] #获取当前目录的上一级目录路径,将文件名和路径切割,然后只取路径
    sys.path.append(curPath.split('xxxx')[0])#以xxxx来分割,且只取第一个,并把它追加到python系统模块中
    rootPath = curPath.split('xxxx')[0]+"xxxx"#按xxxx分割后,取第一个后,在接上xxxx
    sys.path.append(filePath)#sys.path是python的搜索模块的路径集
    sys.path.append(rootPath)
    

      

  • 相关阅读:
    Zabbix 单位换算
    Confluence6.9配置邮件服务器
    Linux内核基础优化
    Nginx跨域问题
    ssh远程登录过程中卡住
    postfix无法启动问题
    mysql-配置文件详解
    Mongodb-副本集部署
    Mongodb-安全配置优化
    Mongodb-简单部署
  • 原文地址:https://www.cnblogs.com/hherbk/p/14272271.html
Copyright © 2011-2022 走看看