0

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?

4Oh4
  • 2,031
  • 1
  • 18
  • 33
  • 1
    It doesn't work for OS X either, I think the authors were looking for `sys.version`, or maybe `platform.python_version`. Note that the package [appears to be deprecated in favour of `munch`](https://github.com/dsc/bunch/issues/32). – jonrsharpe May 26 '16 at 21:31
  • Indeed, `platform.version()` returns the OS version (e.g. 6.1.xxxx for Windows 7), not the Python version. – kindall May 26 '16 at 21:33
  • And `munch` [has a working version check](https://github.com/Infinidat/munch/blob/master/munch/python3_compat.py#L3). – jonrsharpe May 26 '16 at 21:37
  • It seems that [`trading_ig` has already updated](https://github.com/ig-python/ig-markets-api-python-library/commit/dc325b32dcfce68a35266de7c09f321e907a1591) but maybe the change hasn't been released yet. – Alex Hall May 26 '16 at 21:41
  • Ah got it - I've been grabbing the package with PIP and getting the old version, and last time I probably cloned the repository from github and got the updated version. Cheers everyone – 4Oh4 May 26 '16 at 21:50

3 Answers3

2

You should change:

import platform

_IS_PYTHON_3 = (platform.version() >= '3')

to:

import sys

_IS_PYTHON_3 = (sys.version >= '3')
malbarbo
  • 10,717
  • 1
  • 42
  • 57
2

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
Gilberto
  • 813
  • 7
  • 17
1

Looks like they got a bit confused.

>>> platform.python_version()
'2.7.10'
Alex Hall
  • 34,833
  • 5
  • 57
  • 89