[英]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:我的机器的规格是:
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 安装不带
wheel
的IbPy2
,消息如下: 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.