Reputation: 2171
I'm trying to run a Python package (ig-markets-api-python-library, it has a share price streaming function), which I've had running before, and am loosing my mind trying to figure out why I can't get it working again. This might be a bit of a noob question, so thanks for the help. I'm running Python 3.5.1 with Anaconda 2.4.1 (64-bit), and I run into the error below:
Traceback (most recent call last):
File "setupStreamer.py", line 8, in <module>
import ig_streamer
File "/ig-tools-python/ig_streamer.py", line 13, in <module>
from trading_ig import (IGService, IGStreamService)
File "/opt/conda/lib/python3.5/site-packages/trading_ig/__init__.py", line 17, in <module>
from .rest import IGService
File "/opt/conda/lib/python3.5/site-packages/trading_ig/rest.py", line 15, in <module>
from .utils import (_HAS_PANDAS, _HAS_BUNCH)
File "/opt/conda/lib/python3.5/site-packages/trading_ig/utils.py", line 21, in <module>
from infi.bunch import bunchify
File "/opt/conda/lib/python3.5/site-packages/infi/bunch/__init__.py", line 31, in <module>
from .python3_compat import *
File "/opt/conda/lib/python3.5/site-packages/infi/bunch/python3_compat.py", line 20, in <module>
iteritems = dict.iteritems
AttributeError: type object 'dict' has no attribute 'iteritems'
So the error is arising because the bunch module is trying to call the iteritems method, but that's a Python 2 method. Looking at the code for python3_compat.py from bunch, it identifies the Python version using the the version() method from plaform, but _IS_PYTHON_3 is always false:
import platform
_IS_PYTHON_3 = (platform.version() >= '3')
...
# dict.iteritems(), dict.iterkeys() is also incompatible
if _IS_PYTHON_3:
iteritems = dict.items
iterkeys = dict.keys
else:
iteritems = dict.iteritems
iterkeys = dict.iterkeys
On my machine, platform.version() returns information about my operating system:
>>> import platform
>>> platform.version()
'#48~14.04.1-Ubuntu SMP Fri Dec 18 10:24:49 UTC 2015'
... and that is in-line with the platform docs. Surely I'm missing something here? Can this code ever work?
Upvotes: 0
Views: 787
Reputation: 863
Confirm: under Ubuntu, pip install trading_ig
does install an old version.
Under Mac it does not occur.
So the right way to install the module is:
(only if you have already installed the module with pip)
$ pip uninstall trading_ig
(and then)
$ git clone https://github.com/ig-python/ig-markets-api-python-library
$ cd ig-markets-rest-api-python-library
$ python setup.py install
Upvotes: 2
Reputation: 11177
You should change:
import platform
_IS_PYTHON_3 = (platform.version() >= '3')
to:
import sys
_IS_PYTHON_3 = (sys.version >= '3')
Upvotes: 2
Reputation: 36033
Looks like they got a bit confused.
>>> platform.python_version()
'2.7.10'
Upvotes: 1