scrtlabs / catalyst

An Algorithmic Trading Library for Crypto-Assets in Python
http://enigma.co
Apache License 2.0
2.49k stars 725 forks source link

Example imports fail #3

Closed bkc39 closed 7 years ago

bkc39 commented 7 years ago

Dear Zipline Maintainers,

Before I tell you about my issue, let me describe my environment:

Environment

Description of Issue

Example

Got an error about an invalid literal. Looks like a typo

Here is how you can reproduce this issue on your machine:

Reproduction Steps

(catalyst-venv) Bens-MacBook-Pro:catalyst bkc$ git branch
* master
(catalyst-venv) Bens-MacBook-Pro:catalyst bkc$ git pull
Already up-to-date.
(catalyst-venv) Bens-MacBook-Pro:catalyst bkc$ python
Python 3.6.1 (default, Apr  4 2017, 09:40:21)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> from catalyst.api import (cancel_order, symbol, record, order_target_value, get_open_orders)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/bkc/Documents/code/projects/catalyst/catalyst/__init__.py", line 20, in <module>
    from . import data
  File "/Users/bkc/Documents/code/projects/catalyst/catalyst/data/__init__.py", line 1, in <module>
    from . import loader
  File "/Users/bkc/Documents/code/projects/catalyst/catalyst/data/loader.py", line 36, in <module>
    from catalyst.curate.poloniex import PoloniexCurator
  File "/Users/bkc/Documents/code/projects/catalyst/catalyst/curate/poloniex.py", line 9
    DT_START        = time.mktime(datetime(2010, 01, 01, 0, 0).timetuple())
                                                  ^
SyntaxError: invalid token

What steps have you taken to resolve this already?

Should be a simple fix. Just logging here

Anything else?

Nope

Sincerely, Ben

bkc39 commented 7 years ago

Looks like this also affects catalyst ingest:

(catalyst-venv) bash-3.2$ catalyst ingest
catalyst ingest
Traceback (most recent call last):
  File "/Users/bkc/Documents/code/projects/catalyst/catalyst-venv/bin/catalyst", line 7, in <module>
    from catalyst.__main__ import main
  File "/Users/bkc/Documents/code/projects/catalyst/catalyst-venv/lib/python3.6/site-packages/catalyst/__init__.py", line 20, in <module>
    from . import data
  File "/Users/bkc/Documents/code/projects/catalyst/catalyst-venv/lib/python3.6/site-packages/catalyst/data/__init__.py", line 1, in <module>
    from . import loader
  File "/Users/bkc/Documents/code/projects/catalyst/catalyst-venv/lib/python3.6/site-packages/catalyst/data/loader.py", line 36, in <module>
    from catalyst.curate.poloniex import PoloniexCurator
  File "/Users/bkc/Documents/code/projects/catalyst/catalyst-venv/lib/python3.6/site-packages/catalyst/curate/poloniex.py", line 9
    DT_START        = time.mktime(datetime(2010, 01, 01, 0, 0).timetuple())

The fix is straightforward, but then this module starts complaining about mixing tabs and spaces. When that is done I get:

(catalyst-venv) Bens-MacBook-Pro:catalyst bkc$ python
Python 3.6.1 (default, Apr  4 2017, 09:40:21)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> from catalyst.api import cancel_order
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/bkc/Documents/code/projects/catalyst/catalyst/__init__.py", line 20, in <module>
    from . import data
  File "/Users/bkc/Documents/code/projects/catalyst/catalyst/data/__init__.py", line 1, in <module>
    from . import loader
  File "/Users/bkc/Documents/code/projects/catalyst/catalyst/data/loader.py", line 37, in <module>
    from catalyst.utils.calendars import get_calendar
  File "/Users/bkc/Documents/code/projects/catalyst/catalyst/utils/calendars/__init__.py", line 16, in <module>
    from .trading_calendar import TradingCalendar
  File "/Users/bkc/Documents/code/projects/catalyst/catalyst/utils/calendars/trading_calendar.py", line 30, in <module>
    from catalyst.utils.calendars._calendar_helpers import (
ModuleNotFoundError: No module named 'catalyst.utils.calendars._calendar_helpers'

Are we sure that the catalyst source directory is added to PYTHONPATH when the virtualenv is fired up?

If not, I can add the .pth to catalyst-venv site packages.

cfromknecht commented 7 years ago

The formatting and indentation problems were solved by this pull request: https://github.com/enigmampc/catalyst/pull/4

For others who encounter the latter bug, this seems to have been caused by running the python interpreter from the repository's working directory, as this causes it to import the source files directly, instead of the importing the files installed in the virtualenv or in the user's site-packages. The above error is failing to find one of the compiled classes, _calendar_helpers, that does not get built in the source directory. It's probably best to avoid importing catalyst from any file in the repo's top-level directory to avoid confusion.

Thanks @bkc39 for your help on this issue!