【问题标题】:What is the right way to import IbPy2 and backtrader?导入 IbPy2 和 backtrader 的正确方法是什么?
【发布时间】:2022-08-19 08:22:34
【问题描述】:

嗨,我在导入 backtrader 和 IbPy2 时遇到问题。当我 pip install 和当我运行时进口反向贸易商在我的 python shell 中,我收到以下错误:

我点安装了这些:

点安装https://github.com/blampe/IbPy/archive/master.zip

点安装反向交易者

我遇到的错误:

Traceback (most recent call last):

  File ~/opt/anaconda3/lib/python3.9/site-packages/IPython/core/interactiveshell.py:3369 in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  Input In [3] in <cell line: 1>
    import backtrader as bt

  File ~/opt/anaconda3/lib/python3.9/site-packages/backtrader/__init__.py:62 in <module>
    from .cerebro import *

  File ~/opt/anaconda3/lib/python3.9/site-packages/backtrader/cerebro.py:35 in <module>
    from .brokers import BackBroker

  File ~/opt/anaconda3/lib/python3.9/site-packages/backtrader/brokers/__init__.py:30 in <module>
    from .ibbroker import IBBroker

  File ~/opt/anaconda3/lib/python3.9/site-packages/backtrader/brokers/ibbroker.py:30 in <module>
    import ib.ext.Order

  File ~/opt/anaconda3/lib/python3.9/site-packages/ib/ext/Order.py:9 in <module>
    from ib.lib import Double, Integer

  File ~/opt/anaconda3/lib/python3.9/site-packages/ib/lib/__init__.py:239
    except (socket.error, ), ex:
                           ^
SyntaxError: invalid syntax

我的机器的规格是:

  • macbook air m1
  • jupyterlabs
  • 蟒蛇

我想我几乎把问题缩小到了 IbPy2 的错。每当我在没有安装 IbPy2 的情况下导入 backtrader 时,它都可以正常工作。但是一旦使用上面的 pip 命令安装了 IbPy2,我就会遇到这个错误。

任何帮助都将不胜感激,这会让我的一周都被困了好几天!先感谢您!

    标签: trading backtrader


    【解决方案1】:

    pip install wheel

    解释:

    • 错误是什么:这是一个 python2 语法错误,因为它在不同版本的 python 上运行。请阅读此答案以了解详细信息。 Python 2 and Python 3.

    • 为什么会出现:因为没有安装wheel,尤其是用pipenv创建虚拟环境时。 pipenv 或者 pip 安装IbPy2 没有wheel 消息是这样的:Using legacy 'setup.py install' for IbPy2, since package 'wheel' is not installed. 然后被识别为Python2编写的代码。

    • 解决方法:先用pip install wheel安装wheel。然后安装IbPy2pip install IbPy2,就可以正确安装并识别为Python3代码。所以你不会再看到 Python2 语法错误了。

    【讨论】:

      猜你喜欢
      • 2016-10-27
      • 2019-09-04
      • 2016-01-11
      • 2019-09-14
      • 1970-01-01
      • 2022-08-19
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      相关资源
      最近更新 更多