amor71 / LiuAlgoTrader

Framework for algorithmic trading

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to launch the backtester_ui due to Streamlit error

akgpt13 opened this issue · comments

After setting up the tool and sourcing the env_vars.sh as source env_vars.sh, the next step as per the documentation is:

streamlit run https://raw.github.com/amor71/LiuAlgoTrader/master/analysis/backtester_ui.py

Below is the output of the above command:

  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8501
  Network URL: http://172.16.17.5:8501


2021-05-31 12:40:05.617 Compute Engine Metadata server unavailable onattempt 1 of 3. Reason: timed out
2021-05-31 12:40:05.685 Compute Engine Metadata server unavailable onattempt 2 of 3. Reason: [Errno 113] No route to host
2021-05-31 12:40:08.688 Compute Engine Metadata server unavailable onattempt 3 of 3. Reason: timed out
2021-05-31 12:40:08.688 Authentication failed using Compute Engine authentication due to unavailable metadata server.

Going to the web browser, below is the error on the webpage:

Below is the error that I receive:
RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'.

Traceback:

File "/home/metacu/pythons/liu_env/lib/python3.8/site-packages/streamlit/script_runner.py", line 338, in _run_script
    exec(code, module.__dict__)
File "/tmp/tmp8h71d3lx/backtester_ui.py", line 17, in <module>
    from liualgotrader.analytics.analysis import (calc_batch_revenue, count_trades,
File "/home/metacu/pythons/liu_env/lib/python3.8/site-packages/liualgotrader/analytics/analysis.py", line 10, in <module>
    from liualgotrader.common.data_loader import DataLoader  # type: ignore
File "/home/metacu/pythons/liu_env/lib/python3.8/site-packages/liualgotrader/common/data_loader.py", line 21, in <module>
    nest_asyncio.apply()
File "/home/metacu/pythons/liu_env/lib/python3.8/site-packages/nest_asyncio.py", line 12, in apply
    loop = loop or asyncio.get_event_loop()
File "/usr/lib/python3.8/asyncio/events.py", line 639, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'

Screenshot:
liu_algo

Thanks for reporting the issue. I pushed a fix, kindly re-try and let me know if the issue resolved or not. Sorry about that.

Thanks for the quick fix. I now have a different error, shown below.

Terminal Log:

  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8501
  Network URL: http://172.16.17.6:8501

2021-05-31 12:04:52.616 Failed to extract font properties from /usr/share/fonts/truetype/noto/NotoColorEmoji.ttf: In FT2Font: Can not load face.  Unknown file format.
2021-05-31 12:04:52.785 generated new fontManager
2021-05-31 12:04:56.070 Compute Engine Metadata server unavailable onattempt 1 of 3. Reason: timed out
2021-05-31 12:04:56.128 Compute Engine Metadata server unavailable onattempt 2 of 3. Reason: [Errno 113] No route to host
2021-05-31 12:04:59.130 Compute Engine Metadata server unavailable onattempt 3 of 3. Reason: timed out
2021-05-31 12:04:59.130 Authentication failed using Compute Engine authentication due to unavailable metadata server.

Browser error

And in the browser at the URL http://localhost:8501/, the error shown is :

ModuleNotFoundError: No module named 'liualgotrader.trading'
Traceback:

File "/home/metacu/anaconda3/envs/quant1/lib/python3.9/site-packages/streamlit/script_runner.py", line 338, in _run_script
    exec(code, module.__dict__)
File "/tmp/tmp4tgngtnf/backtester_ui.py", line 20, in <module>
    from liualgotrader.analytics.analysis import (calc_batch_revenue, count_trades,
File "/home/metacu/anaconda3/envs/quant1/lib/python3.9/site-packages/liualgotrader/analytics/analysis.py", line 16, in <module>
    from liualgotrader.trading.trader_factory import trader_factory

Adding to the previous info, the command pip install liualgotrader executes successfully.

Sure, I'm still trying to figure out. I tried with the python virtual environments and ended up spending several hours trying to get it to work on a plain vanilla Ubuntu Mate 20.04 set up from scratch. I think the documentation/wiki needs more improvement for setup so that it is easy to get started for anyone and I would be happy to contribute once I figure it out.

Below is the issue I'm currently stuck at with the venv style setup.

(env) metacu@ubuntu:~/liu/LiuAlgoTrader-0.3.0/liu_samples$ streamlit run https://raw.github.com/amor71/LiuAlgoTrader/master/analysis/backtester_ui.py
Traceback (most recent call last):
  File "/usr/local/bin/streamlit", line 33, in <module>
    sys.exit(load_entry_point('streamlit==0.82.0', 'console_scripts', 'streamlit')())
  File "/usr/local/bin/streamlit", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib/python3.9/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 855, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/local/lib/python3.9/dist-packages/streamlit-0.82.0-py3.9.egg/streamlit/__init__.py", line 76, in <module>
    from streamlit.delta_generator import DeltaGenerator as _DeltaGenerator
  File "/usr/local/lib/python3.9/dist-packages/streamlit-0.82.0-py3.9.egg/streamlit/delta_generator.py", line 63, in <module>
    from streamlit.elements.image import ImageMixin
  File "/usr/local/lib/python3.9/dist-packages/streamlit-0.82.0-py3.9.egg/streamlit/elements/image.py", line 24, in <module>
    from PIL import Image, ImageFile
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 94, in <module>
    from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/usr/lib/python3/dist-packages/PIL/__init__.py)

I am again trying with the conda style setup and again stuck with the same error:

telegram-cloud-photo-size-1-5021774929439336708-y

File "/home/metacu/anaconda3/envs/algotrading/lib/python3.9/site-packages/streamlit/script_runner.py", line 338, in _run_script
    exec(code, module.__dict__)
File "/tmp/tmpcyxo6aui/backtester_ui.py", line 20, in <module>
    from liualgotrader.analytics.analysis import (calc_batch_revenue, count_trades,
File "/home/metacu/anaconda3/envs/algotrading/lib/python3.9/site-packages/liualgotrader/analytics/analysis.py", line 16, in <module>
    from liualgotrader.trading.trader_factory import trader_factory

Thanks! That would be super helpful. I have messaged you on Gitter chat.

Got it working, thanks to @amor71.

If anyone is struggling with installation, here's how you can do it on a fresh Ubuntu 20.04 instance:

$ sudo apt update
$ sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable"
$ sudo apt-get update
$sudo apt install docker-ce -y
$ sudo usermod -aG docker $USER

Log out and log back in

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.28.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt update
$ sudo apt install python3.9
$ sudo apt install python3-pip
$ sudo apt install python3.9-venv
$ mkdir venv
$ python3.9 -m venv ~/venv/liu
$ source ~/venv/liu//bin/activate
$ mkdir ~/liu ; cd ~/liu
$ pip install liualgotrader
$ export (ALPACA KEYS)=xxx
$ liu QuickStart