Error when using zipline

Hi,

I am wondering if any body has encountered the same error when using zipline. For example, I wanted to run an algofile using cmd line, but got the following error:

zipline run -f ~/1_files/ml4t/zipline/examples/buyapple.py --start 2016-1-1 --end 2018-1-1 -o buyapple_out.pickle --no-benchmark

Traceback (most recent call last):
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/exchange_calendars/utils/memoize.py”, line 47, in get
return self._cache[instance]
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/weakref.py”, line 383, in getitem
return self.data[ref(key)]
KeyError: <weakref at 0x7f8642862bd0; to ‘BcolzMinuteBarReader’ at 0x7f8642848790>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/Users/Chen/miniconda3/envs/ml4t/bin/zipline”, line 11, in
sys.exit(main())
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/click/core.py”, line 1130, in call
return self.main(*args, **kwargs)
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/click/core.py”, line 1055, in main
rv = self.invoke(ctx)
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/click/core.py”, line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/click/core.py”, line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/click/core.py”, line 760, in invoke
return __callback(*args, **kwargs)
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/zipline/main.py”, line 106, in _
return f(*args, **kwargs)
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/click/decorators.py”, line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/zipline/main.py”, line 300, in run
return _run(
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/zipline/utils/run_algo.py”, line 163, in _run
data = DataPortal(
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/zipline/data/data_portal.py”, line 183, in init
last_minutes = [
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/zipline/data/data_portal.py”, line 184, in
reader.last_available_dt
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/exchange_calendars/utils/memoize.py”, line 49, in get
self._cache[instance] = val = self._get(instance)
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/zipline/data/minute_bars.py”, line 953, in last_available_dt
_, close = self.calendar.open_and_close_for_session(self._end_session)
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/exchange_calendars/exchange_calendar.py”, line 1080, in open_and_close_for_session
session_label = parse_session(self, session_label, “session_label”)
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/exchange_calendars/calendar_helpers.py”, line 273, in parse_session
ts = parse_date(session, param_name)
File “/Users/Chen/miniconda3/envs/ml4t/lib/python3.8/site-packages/exchange_calendars/calendar_helpers.py”, line 217, in parse_date
if not (ts.tz is None or ts.tz.zone == “UTC”):
AttributeError: ‘datetime.timezone’ object has no attribute ‘zone’

Does anyone have any idea how to solve this? Thanks a lot!

hi,
getting the same error… were you able to resolve this?

Nope. Will let you know when figure this out.

Just FYI. I solved the problem by upgrading zipline-reloaded to the newest version.

Thanks! I updated to 3.0.3 and running on Python 3.10… now getting a different error

AttributeError: ‘datetime.timezone’ object has no attribute ‘key’

You probably can avoid that error by making start and end time unaware, ie, not using .tz_localize("UTC").

1 Like