Description
Title:
AttributeError: 'ZMQInteractiveShell' object has no attribute 'magic' when importing vectorbt
Text:
Description:
When trying to import vectorbt in my Python environment, I encountered the following error:
AttributeError: 'ZMQInteractiveShell' object has no attribute 'magic'
This happens when running:
import vectorbt as vbt
Error Traceback:
AttributeError Traceback (most recent call last)
Cell In[1], line 3
1 # %%
2 import os
----> 3 import vectorbt as vbt
File /opt/homebrew/Caskroom/miniconda/base/envs/venv/lib/python3.12/site-packages/vectorbt/init.py:23
21 from vectorbt.signals import *
22 from vectorbt.records import *
---> 23 from vectorbt.portfolio import *
24 from vectorbt.labels import *
25 from vectorbt.messaging import *
File /opt/homebrew/Caskroom/miniconda/base/envs/venv/lib/python3.12/site-packages/vectorbt/portfolio/init.py:6
1 # Copyright (c) 2021 Oleg Polakow. All rights reserved.
2 # This code is licensed under Apache 2.0 with Commons Clause license (see LICENSE.md for details)
4 """Modules for working with portfolios."""
----> 6 from vectorbt.portfolio.base import Portfolio
7 from vectorbt.portfolio.enums import *
8 from vectorbt.portfolio.logs import Logs
File /opt/homebrew/Caskroom/miniconda/base/envs/venv/lib/python3.12/site-packages/vectorbt/portfolio/base.py:1424
1422 from vectorbt.generic.plots_builder import PlotsBuilderMixin
1423 from vectorbt.generic.stats_builder import StatsBuilderMixin
...
311 return True
312 if shell == "TerminalInteractiveShell":
313 # Terminal running IPython
AttributeError: 'ZMQInteractiveShell' object has no attribute 'magic'
System Information:
• OS: macOS Sequoia 15.3.2
• Python Version: 3.12
• vectorbt Version: 0.27.2
• ipykernel: 6.29.5
• Jupyter/IPython: 9.0.2
Steps to Reproduce:
1. Install vectorbt in a Python 3.12 environment:
pip install vectorbt
2. Run the following command:
import vectorbt as vbt
3. The error occurs during import.
Expected Behavior:
vectorbt should import without raising an attribute error.
Possible Cause:
• This issue may be related to incompatibility between vectorbt and IPython/Jupyter.
• The error originates from ZMQInteractiveShell, which is used in Jupyter-based environments.
Workarounds Attempted:
• Tried running in a standard Python shell instead of Jupyter, but the issue persists.
• Verified the installed versions of IPython and vectorbt.
• Attempted reinstalling vectorbt and IPython:
pip install --upgrade vectorbt ipython
Request for Help:
• Has anyone encountered this issue before?
• Is there a specific environment setup required to run vectorbt with Python 3.12?
• Could this be an incompatibility with Jupyter, and if so, is there a recommended fix?
Any guidance or suggestions would be greatly appreciated!