简体   繁体   English

导入 IbPy2 和 backtrader 的正确方法是什么?

[英]What is the right way to import IbPy2 and backtrader?

Hi i am having trouble importing backtrader and IbPy2.嗨,我在导入 backtrader 和 IbPy2 时遇到问题。 When i pip install both and when i run import backtrader in my python shell i get the following error:当我安装 pip 并且当我在我的 python shell 中运行import backtrader时,我收到以下错误:

i pip installed these:我 pip 安装了这些:

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

pip install backtrader pip 安装反向交易者

The error i encountered:我遇到的错误:

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

The specs of my machine are:我的机器的规格是:

  • macbook air m1 MacBook Air M1
  • jupyterlabs jupyterlabs
  • anaconda anaconda

I think i pretty much narrowed the problem down to IbPy2's fault.我想我几乎把问题缩小到了 IbPy2 的错。 Whenever i import backtrader with no IbPy2 installed it works fine.每当我在没有安装 IbPy2 的情况下导入 backtrader 时,它都可以正常工作。 But soon as IbPy2 is installed using the above pip command i encounter this error.但是一旦使用上面的 pip 命令安装了 IbPy2,我就会遇到这个错误。

Any help is appreciated and would make my week I have been stuck for days!任何帮助都将不胜感激,这会让我的一周都被困了好几天! Thank you in advance!先感谢您!

pip install wheel

Explanation:解释:

  • What is the error: It is a python2 syntax error because it runs on different version of python.错误是什么:这是一个 python2 语法错误,因为它在不同版本的 python 上运行。 Please read this answer for detail.请阅读此答案以了解详细信息。 Python 2 and Python 3. Python 2 和 Python 3。

  • Why does it occur: Because there is no wheel installed, especially when you create a virtual environment with pipenv .为什么会发生:因为没有安装wheel ,尤其是当您使用pipenv创建虚拟环境时。 Pipenv or pip installs IbPy2 without wheel and the message is like this: Using legacy 'setup.py install' for IbPy2, since package 'wheel' is not installed. Pipenv 或 pip 安装不带wheelIbPy2 ,消息如下: Using legacy 'setup.py install' for IbPy2, since package 'wheel' is not installed. And then it was recognized as the code written in Python2.然后它被识别为用Python2编写的代码。

  • How to solve: Install wheel first with pip install wheel .解决方法:先装wheel ,用pip install wheel And then install IbPy2 with pip install IbPy2 , then it will be properly installed and recognized as Python3 code.然后使用 pip install IbPy2 pip install IbPy2 ,然后它将被正确安装并识别为 Python3 代码。 So you will not see the Python2 syntax error anymore.所以你不会再看到 Python2 语法错误了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 定义MQL4“静态类方法的#import”的正确方法是什么? - What is the correct way to define MQL4 “#import of static class methods”? Python-Ibpy返回有效的订单ID - Python - Ibpy return valid order id 指标是否为每个新柱计算? [backtrader] - Does indicators calculates for each new bar? [backtrader] 在Python中解析这些字符串的最佳方法是什么? - What is the optimal way to parse these strings in Python? 在这个 class 中测试这个“setUp()”function 的正确方法是什么? - What's the correct way to test this “setUp()” function inside this class? 在 pinescript 警报中有什么方法可以检测图表的时间范围,然后根据它发送警报? - In pinescript alerts is there any way to detect what the timeframe of the chart and then send alerts based on that? 在 Python 中重复执行 function 的最佳方法是什么? - What is the best way to repeatedly execute a function in Python? 交易申请中低延迟的原则是什么? - what is the principle of low latency in trading application? Pine-Script Labeling - 有什么方法可以四舍五入吗? - Pine-Script Labeling - Any way to round the numbers? 有没有办法只在吞噬蜡烛比前两根蜡烛大时发出警报? - Is there a way to only alert when an engulfing candle is bigger than the previous 2 candles?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM