1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Python - failed to import external python program under different folder

Discussão em 'Python' iniciado por Stack, Outubro 25, 2024 às 10:22.

  1. Stack

    Stack Membro Participativo

    I have a web-based Python application using Flask and a Python application, tradingBot. I copied my tradingBot application to a Web-based application under a different directory so I can call the tradingBot application. the directory structure like below:

    • myTradingBot
      • apps
        • home
          • routes.py
        • static
          • css
          • js
        • template
          • home
            • dashboard.html
            • tradingDemo.html
        • autoTrade <== want to import this package to routes.py
          • bot.py
          • tradelib.py

    I have tried the following in the route.py file with no success

    try:
    from apps.home import blueprint
    import pyasx.data.companies

    import pandas as pd
    import plotly
    import os
    import sys
    sys.path.append(os.path.abspath("/myTradingBot/apps/autoTrade/"))
    import bot

    print("ALl modules Loaded ")
    except Exception as e:
    print("Error : {} ".format(e))

    @blueprint.route("/stock-movement", methods=['GET', 'POST'])
    def stockMovement():ry:

    companyInfo = pyasx.data.companies.get_company_info(company_share_code)
    bot.tradeBotStart()


    It return an error stating that: bot is undefined.

    Note: in my bot.py, i have alredy commented out the protected main

    def tradeBotStart

    print("start - TradeBotStart")
    api = tradeapi.REST(gvars.API_KEY, gvars.API_SECRET_KEY, api_version='v2')


    #if __name__ == '__main__':
    # main()
    # #main(sys.argv[1:])


    Please advise

    Continue reading...

Compartilhe esta Página