#779·vectorbt

在导入 vectorbt 时,AttributeError: 'ZMQInteractiveShell' 对象没有属性 'magic'

作者: homerokzam创建于 2025年3月14日更新于 2025年8月6日

Title: AttributeError: 'ZMQInteractiveShell' object has no attribute 'magic' when importing vectorbt 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 # %% import os import vectorbt as vbt File /opt/homebrew/Caskroom/miniconda/base/envs/venv/lib/python3.12/site-packages/vectorbt/__init__.py:23 from vectorbt.signals import * from vectorbt.records import * from vectorbt.portfolio import * from vectorbt.labels import * from vectorbt.messaging import * File /opt/homebrew/Caskroom/miniconda/base/envs/venv/lib/python3.12/site-packages/vectorbt/portfolio/__init__.py:6 # Copyright (c) 2021 Oleg Polakow. All rights reserved. # This code is licensed under Apache 2.0 with Commons Clause license (see LICENSE.md for details) """Modules for working with portfolios.""" from vectorbt.portfolio.base import Portfolio from vectorbt.portfolio.enums import * from vectorbt.portfolio.logs import Logs File /opt/homebrew/Caskroom/miniconda/base/envs/venv/lib/python3.12/site-packages/vectorbt/portfolio/base.py:1424 from vectorbt.generic.plots_builder import PlotsBuilderMixin from vectorbt.generic.stats_builder import StatsBuilderMixin ... 311 return True if shell == "TerminalInteractiveShell": # 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...

内容来源: polakowo/vectorbt