ranaroussi / quantstats

Portfolio analytics for quants, written in Python
Apache License 2.0
4.73k stars 827 forks source link

Dependency on IPython not declared in requirements #295

Open tschm opened 1 year ago

tschm commented 1 year ago

IPython is used in reports to generate html files... Please add the dependency

sawaca96 commented 10 months ago

any update?

brent-ridian commented 6 months ago

First, Ran, thanks much for this library. If ever you find yourself in my city, first 10 beers are on me.

This is indeed a bug.

I just got burned by this too.

I created a new venv for my project yesterday in order to use quantstats functions like cagr, sharpe, sortino, etc. I used the very latest version, QuantStats == 0.0.62

But when I tried to use those functions in my code with that new venv, I get this error:

Traceback (most recent call last):
  File "C:\brilly\virtualenvs\quant-venv\lib\site-packages\quantstats\reports.py", line 33, in <module>
    from IPython.display import display as iDisplay, HTML as iHTML
ModuleNotFoundError: No module named 'IPython'

If you look at reports.py (which my code does not directly use--it must be some kind of transitive dependency), the offending code is this section:

try:
    from IPython.display import display as iDisplay, HTML as iHTML
except ImportError:
    from IPython.core.display import display as iDisplay, HTML as iHTML

So, the fix will either be to add iPython as a dependency in requirements.txt (likely the easiest route) or else code like reports.py above will need to add an except clause for ModuleNotFoundError and have some kind of fall back for display and HTML.