quantstats icon indicating copy to clipboard operation
quantstats copied to clipboard

AttributeError: 'ZMQInteractiveShell' object has no attribute 'magic'

Open Viddesh1 opened this issue 10 months ago • 1 comments

Hello,

Thank you creating this project and making this open source.

I was just running through the readme.md file in vscode jupyter notebook but received an error.

Python 3.12.5

import matplotlib
%matplotlib inline

import quantstats as qs

# extend pandas functionality with metrics, etc.
qs.extend_pandas()

# fetch the daily returns for a stock
stock = qs.utils.download_returns('META')

# show sharpe ratio
qs.stats.sharpe(stock)

# or using extend_pandas() :)
stock.sharpe()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[13], line 4
      1 import matplotlib
      2 get_ipython().run_line_magic('matplotlib', 'inline')
----> 4 import quantstats as qs
      6 # extend pandas functionality with metrics, etc.
      7 qs.extend_pandas()

File c:\Users\Admin\Desktop\document\.venv\Lib\site-packages\quantstats\__init__.py:31
     28 __all__ = ["stats", "plots", "reports", "utils", "extend_pandas"]
     30 # try automatic matplotlib inline
---> 31 utils._in_notebook(matplotlib_inline=True)
     34 def extend_pandas():
     35     """
     36     Extends pandas by exposing methods to be used like:
     37     df.sharpe(), df.best('day'), ...
     38     """

File c:\Users\Admin\Desktop\document\.venv\Lib\site-packages\quantstats\utils.py:310, in _in_notebook(matplotlib_inline)
    307 if shell == "ZMQInteractiveShell":
    308     # Jupyter notebook or qtconsole
    309     if matplotlib_inline:
--> 310         get_ipython().magic("matplotlib inline")
    311     return True
    312 if shell == "TerminalInteractiveShell":
    313     # Terminal running IPython

AttributeError: 'ZMQInteractiveShell' object has no attribute 'magic'

Viddesh1 avatar Mar 16 '25 15:03 Viddesh1

Please push the fix! I am fixing this by hand in my codebase. And yes, I have quantstats 0.0.64. The only change in utils.py from 63 -> 64 seems to be a change in the version number, no "magic" fix.

andrewzachary avatar Apr 27 '25 00:04 andrewzachary

I've created a fork and made a release. In addition to fixing this bug (Python 3.12 support), I've also added compatibility for Python 3.13. I forked the project and published it as quantstats-reloaded to ensure more active updates and maintenance of the library.

Please find release at https://pypi.org/project/quantstats-reloaded/

zillionare avatar Jun 16 '25 08:06 zillionare