UnicodeDecodeError encountered when running zipline installed with Pip3 on WSL

43 views
Skip to first unread message

Tuấn Nguyễn Thế

unread,
Nov 30, 2017, 5:04:31 AM11/30/17
to Zipline Python Opensource Backtester
Dear everyone,

I have been experimenting with Zipline on WSL environment. I previously installed and ran some example fine (on the same WSL environment using conda).

Then, I removed conda and using pip3 to install zipline. I also added the csvdir.py and successfully import from csv. Then, when i tried to run the buyapple.pl example. I have the following error:

(3.5) tuannt@PNCPT-TUANNT:~/envs/3.5/lib/python3.5/site-packages/zipline/examples$ zipline run -f buyapple.py --start 2017-9-1 --end 2017-11-20 -o buy_apple.pickle
[2017-11-30 09:50:26.722906] INFO: Loader: Cache at /home/tuannt/.zipline/data/SPY_benchmark.csv does not have data from 1990-01-02 00:00:00+00:00 to 2017-11-28 00:00:00+00:00.

[2017-11-30 09:50:26.725061] INFO: Loader: Downloading benchmark data for 'SPY' from 1989-12-29 00:00:00+00:00 to 2017-11-28 00:00:00+00:00
Traceback (most recent call last):
  File "/home/tuannt/envs/3.5/bin/zipline", line 11, in <module>
    sys.exit(main())
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/zipline/__main__.py", line 97, in _
    return f(*args, **kwargs)
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/zipline/__main__.py", line 240, in run
    environ=os.environ,
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/zipline/utils/run_algo.py", line 132, in _run
    env = TradingEnvironment(asset_db_path=connstr, environ=environ)
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/zipline/finance/trading.py", line 99, in __init__
    self.bm_symbol,
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/zipline/data/loader.py", line 166, in load_market_data
    environ,
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/zipline/data/loader.py", line 230, in ensure_benchmark_data
    last_date,
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/zipline/data/benchmarks.py", line 50, in get_benchmark_returns
    last_date
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/pandas_datareader/data.py", line 137, in DataReader
    session=session).read()
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/pandas_datareader/base.py", line 181, in read
    params=self._get_params(self.symbols))
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/pandas_datareader/base.py", line 79, in _read_one_data
    out = self._read_url_as_StringIO(url, params=params)
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/pandas_datareader/base.py", line 98, in _read_url_as_StringIO
    out.write(bytes_to_str(text))
  File "/home/tuannt/envs/3.5/lib/python3.5/site-packages/pandas/compat/__init__.py", line 72, in bytes_to_str
    return b.decode(encoding or 'utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xec in position 351: invalid continuation byte

The "buyapple.py" is unchanged. Can anyone help point me to the right direction?

Regards,

TuanNT

Tuấn Nguyễn Thế

unread,
Nov 30, 2017, 10:53:57 PM11/30/17
to Zipline Python Opensource Backtester
Resolved --

The issue was pandas-datareader returned UnicodeDecodeError if getting SPY benchmark data from Google.

How to fix: use yahoo (in ../zipline/data/benchmarks.py) instead of 'google'.

Alex Treichel

unread,
Dec 1, 2017, 3:14:34 AM12/1/17
to Zipline Python Opensource Backtester
I have the same problem. How did you change in in the benchmarks.py?

Alex Treichel

unread,
Dec 1, 2017, 8:08:33 AM12/1/17
to Zipline Python Opensource Backtester
nvm. I looked into it and it's pretty obvious. Thank you.


On Thursday, 30 November 2017 11:04:31 UTC+1, Tuấn Nguyễn Thế wrote:
Message has been deleted

Justin Maat

unread,
Dec 4, 2017, 11:34:27 AM12/4/17
to Zipline Python Opensource Backtester
Thanks so much for this, been struggling all morning looking through the problem.

I noticed this in the release notes, wondering if it's related?


"We also saw breaking changes occur from Yahoo changing their API endpoint, thus preventing users from downloading benchmark data needed for backtests. Since that change, we have swapped out Yahoo-related benchmarking code with references to Google Finance and have removed all deprecated Yahoo code, including the usage of custom Yahoo bundles."
Reply all
Reply to author
Forward
0 new messages