0

I am trying to run the following code from this repository.

https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library

hp.visualize(images, column=3, fig_size=(20,10))

It gives me following error. How can I fix this?

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "Helpers.py", line 51, in visualize
    f,axes= plt.subplots(row, column, figsize=fig_size)
  File "/home/.local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 1187, in subplots
    gridspec_kw=gridspec_kw)
  File "/home/.local/lib/python2.7/site-packages/matplotlib/figure.py", line 1362, in subplots
    axarr = np.empty((nrows, ncols), dtype=object)
TypeError: 'float' object cannot be interpreted as an index
Miki
  • 40,887
  • 13
  • 123
  • 202
nikki
  • 365
  • 4
  • 20
  • https://stackoverflow.com/search?q=TypeError%3A+%27float%27+object+cannot+be+interpreted+as+an+index – Joe Jun 04 '20 at 17:07
  • Does this answer your question? [TypeError: 'float' object cannot be interpreted as an index, how to solve it?](https://stackoverflow.com/questions/59717241/typeerror-float-object-cannot-be-interpreted-as-an-index-how-to-solve-it) – Joe Jun 04 '20 at 17:08
  • no, it did not help. – nikki Jun 04 '20 at 17:34

1 Answers1

1

I believe the repo that you are trying to use requires Python3.x(though it's not explicitly mentioned anywhere ) and you seem to be using Python2.7.

The error

TypeError: 'float' object cannot be interpreted as an index

seems to me that one of the parameters in the line is passing a float value as an index which is not accepted in Python2.x and will be fine in Python3.x.

Simply use Python3.x and it should solve your problem.

AzyCrw4282
  • 7,222
  • 5
  • 19
  • 35
  • thanks for answering, could you pls tell me how do I specify python 3 for this specific code? when I run the program it uses python 2 by default. – nikki Jun 05 '20 at 14:33
  • Are you using Jupyter Notebook? If so just configure it to use python3 instead, see [here](https://stackoverflow.com/questions/28831854/how-do-i-add-python3-kernel-to-jupyter-ipython) – AzyCrw4282 Jun 05 '20 at 15:15
  • I am using Pycharm. How could I configure it on Pycharm? – nikki Jun 05 '20 at 15:16
  • use python3. Look up on how you can install and use python3 for pycharm. Alternatively, you may also wish to do it in Jupiter notebook as done in the github repo. – AzyCrw4282 Jun 05 '20 at 15:17
  • My Pycharm is based on python 3. However, when I run the code using Pycharm terminal, it automatically uses Python v2. I do not have any clue why this happens. – nikki Jun 05 '20 at 15:24
  • Because your terminal within pycharm is separate from your IDE. you can try running `python --version` and it would give you python 2.x.x. You need to set the path in your environment to be python3 instead, see [here](https://feaforall.com/how-to-install-python-3-on-windows-and-set-the-path/) – AzyCrw4282 Jun 05 '20 at 15:25
  • yes, it does give me python 2.x.x. Is there any way that I can fix it? or should forget using pycharm terminal? – nikki Jun 05 '20 at 15:25
  • Thanks, I am ubuntu and that changing the default version might cause problems to my Ubuntu system. – nikki Jun 05 '20 at 15:31