edeng23 / binance-trade-bot

Automated cryptocurrency trading bot
GNU General Public License v3.0
7.94k stars 2.2k forks source link

ImportError: cannot import name 'escape' from 'jinja2' #489

Open sssemil opened 2 years ago

sssemil commented 2 years ago

If you try running python backtest.py, you will get this error:

Traceback (most recent call last):
  File "/home/emil/Projects/binance-trade-bot/backtest.py", line 3, in <module>
    from binance_trade_bot import backtest
  File "/home/emil/Projects/binance-trade-bot/binance_trade_bot/__init__.py", line 1, in <module>
    from .backtest import backtest
  File "/home/emil/Projects/binance-trade-bot/binance_trade_bot/backtest.py", line 8, in <module>
    from .binance_api_manager import BinanceAPIManager
  File "/home/emil/Projects/binance-trade-bot/binance_trade_bot/binance_api_manager.py", line 10, in <module>
    from .binance_stream_manager import BinanceCache, BinanceOrder, BinanceStreamManager, OrderGuard
  File "/home/emil/Projects/binance-trade-bot/binance_trade_bot/binance_stream_manager.py", line 9, in <module>
    from unicorn_binance_websocket_api import BinanceWebSocketApiManager
  File "/home/emil/Projects/binance-trade-bot/venv/lib/python3.10/site-packages/unicorn_binance_websocket_api/__init__.py", line 3, in <module>
    from unicorn_binance_websocket_api.manager import BinanceWebSocketApiManager
  File "/home/emil/Projects/binance-trade-bot/venv/lib/python3.10/site-packages/unicorn_binance_websocket_api/manager.py", line 40, in <module>
    from unicorn_binance_websocket_api.restserver import BinanceWebSocketApiRestServer
  File "/home/emil/Projects/binance-trade-bot/venv/lib/python3.10/site-packages/unicorn_binance_websocket_api/restserver.py", line 36, in <module>
    from flask_restful import Resource
  File "/home/emil/Projects/binance-trade-bot/venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 3, in <module>
    from flask import request, url_for, current_app
  File "/home/emil/Projects/binance-trade-bot/venv/lib/python3.10/site-packages/flask/__init__.py", line 14, in <module>
    from jinja2 import escape
ImportError: cannot import name 'escape' from 'jinja2' (/home/emil/Projects/binance-trade-bot/venv/lib/python3.10/site-packages/jinja2/__init__.py)

Similar issue in another project - https://github.com/pallets/flask/issues/4494

sssemil commented 2 years ago

Specify this in your requirements.txt as a workaround:

jinja2==3.0.3
flask==1.1.1
znake77 commented 2 years ago

Hi had the same issue so i tried your workaround but it gives me now another error:

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 185, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.8/runpy.py", line 144, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.8/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/home/user/Documents/binance-bot/binance-trade-bot/binance_trade_bot/__init__.py", line 1, in <module>
    from .backtest import backtest
  File "/home/user/Documents/binance-bot/binance-trade-bot/binance_trade_bot/backtest.py", line 8, in <module>
    from .binance_api_manager import BinanceAPIManager
  File "/home/user/Documents/binance-bot/binance-trade-bot/binance_trade_bot/binance_api_manager.py", line 10, in <module>
    from .binance_stream_manager import BinanceCache, BinanceOrder, BinanceStreamManager, OrderGuard
  File "/home/user/Documents/binance-bot/binance-trade-bot/binance_trade_bot/binance_stream_manager.py", line 9, in <module>
    from unicorn_binance_websocket_api import BinanceWebSocketApiManager
  File "/home/user/Documents/binance-bot/binance-trade-bot/venv/lib/python3.8/site-packages/unicorn_binance_websocket_api/__init__.py", line 3, in <module>
    from unicorn_binance_websocket_api.unicorn_binance_websocket_api_manager import BinanceWebSocketApiManager
  File "/home/user/Documents/binance-bot/binance-trade-bot/venv/lib/python3.8/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_manager.py", line 40, in <module>
    from .unicorn_binance_websocket_api_restserver import BinanceWebSocketApiRestServer
  File "/home/user/Documents/binance-bot/binance-trade-bot/venv/lib/python3.8/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_restserver.py", line 36, in <module>
    from flask_restful import Resource
  File "/home/user/Documents/binance-bot/binance-trade-bot/venv/lib/python3.8/site-packages/flask_restful/__init__.py", line 3, in <module>
    from flask import request, url_for, current_app
  File "/home/user/Documents/binance-bot/binance-trade-bot/venv/lib/python3.8/site-packages/flask/__init__.py", line 21, in <module>
    from .app import Flask
  File "/home/user/Documents/binance-bot/binance-trade-bot/venv/lib/python3.8/site-packages/flask/app.py", line 32, in <module>
    from werkzeug.wrappers import BaseResponse
ImportError: cannot import name 'BaseResponse' from 'werkzeug.wrappers' (/home/user/Documents/binance-bot/binance-trade-bot/venv/lib/python3.8/site-packages/werkzeug/wrappers/__init__.py)
znake77 commented 2 years ago

For those having this issue is because the last version of Werkzeug are not compatible. Ref: https://github.com/postmanlabs/httpbin/issues/673

Solved this issue with : pip install Werkzeug==2.0.3

Mundo-Desconocido commented 2 years ago

For those having this issue is because the last version of Werkzeug are not compatible. Ref: postmanlabs/httpbin#673

Solved this issue with : pip install Werkzeug==2.0.3

it doesn't work either

B-Mbengue commented 2 years ago

There are some updates on Jinja2 package. To solve the issue change in the "requirements" the flask version to flask=2.1.0 and re-run the code

ekurer commented 2 years ago

Hey @edeng23 can you update requirements? Or should I submit a PR?

edeng23 commented 2 years ago

Can you please submit a PR?