Python modules missing

346 views
Skip to first unread message

Jade Mathilde Sourisse

unread,
Aug 9, 2021, 4:18:29 AM8/9/21
to Bonsai Users

Dear Dr Lopes and Bonsai community,

I am Jade, a PhD student at the University of Hong Kong and for my research project I am attempting to use Bonsai for behavioural tracking and analysis of larval zebrafish. I am not yet familiar with Python language and I am encountering an issue in my workflow, I am hoping you could help me. I am running Bonsai 2.6.2 on Windows 10 and I am using a workflow from the BonZeb package, that allows multi animal tracking. My issue is at the end of my workflow, as a code contained in « Python Transform » cannot be ran. Bonsai responds « No module named csv » after trying to import csv in that script. I thought modules like csv and os were inherent to Python so I dont know what to do.I have installed Python and IronPython packages in Bonsai, along with the Bonsai Starter pack so I think it should be fine, not to mention i have anaconda3 on my laptop as well.

I have attached the workflow file for your reference, I think it should be helpful. Also I copied the script in which I have an issue at the bottom of this discussion for you to see. As I have downloaded them from the Github repository of BonZeb it should not contain mistakes, but who knows…
I am a bit desperate because I have worked on previous steps for a while now and was really excited about how well things seemed to be going. I hope it is a silly mistake and that you could help me with little to no hassle too.

Thank you very much for your attention and please do not hesitate to contact me if you need any additional information.
Best regards,

 Jade Mathilde SOURISSE

import csv

import os

csv_writer = None

csv_file = None

filename = None

 

def unload():

  global filename, csv_file, csv_writer

  if filename is not None:

    filename = None

  if csv_file is not None:

    csv_file.close()

    csv_file = None

  if csv_writer is not None:

    csv_writer = None

 

@returns(bool)

def process(value):

  global filename, csv_file, csv_writer

  if filename is None:

    filename = "tracking_results.csv"

    csv_file = open(filename, 'wb')

    csv_writer = csv.writer(csv_file, delimiter = ',')

  n_fish_list = []

  for tail_points in value.Item1:

    tail_points_list = []

    for tail_point in tail_points:

      tail_points_list.append(str(tail_point))

    n_fish_list.append(str(tail_points_list))

  csv_writer.writerow(n_fish_list)

  return True

bonzeb_multi_animal_tracking_pipeline.bonsai

Gonçalo Lopes

unread,
Aug 11, 2021, 8:41:09 PM8/11/21
to Jade Mathilde Sourisse, Bonsai Users
Hi Jade and welcome to the forums,

First of all, thanks for following up offline by email as this allowed me to realize that some forum posts were being redirected to my spam folder, which has now been fixed.

Regarding importing the csv module, this should indeed come built into the python standard library, which should be installed by default with IronPython. Can you confirm that you have the package IronPython Standard Library installed in the package manager?

Hope this helps!

--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/ea4be747-2f86-4a63-b0f7-966c50ca87f8n%40googlegroups.com.

Jade Mathilde Sourisse

unread,
Aug 11, 2021, 9:31:26 PM8/11/21
to Bonsai Users
Dear Goncalo, 
Thank you for your reply (and glad I could help with the spam thing!). I can confirm you that IronPython Standard Library 2.7.11 is installed in my Package Manager yes, and so is IronPython. This is why I am puzzled by the error message... Any ideas as to why modules are not recognized?
Thanks for following up!
Best, 

Jade

Gonçalo Lopes

unread,
Aug 12, 2021, 11:39:06 PM8/12/21
to Jade Mathilde Sourisse, Bonsai Users
Hi Jade,

The issue is with the version of your Python standard library. The scripting package expects IronPython std lib 2.7.5 and not 2.7.11.

I'm not sure how you ended up with an upgraded version, since the default package manager sources only point to 2.7.5 and the scripting package also depends on 2.7.5, but if you revert back to that version, the script should work.

Hope this helps!

Jade Mathilde Sourisse

unread,
Aug 14, 2021, 8:47:54 AM8/14/21
to Bonsai Users
Dear Goncalo, 
Thank you for pointing that out! Strange indeed that I end up with this version... If I uninstall IronPython library and depending packages though, I am only offered to reinstall 2.7.11 though, I am not sure how to go around that problem. Should I install IronPython on my computer manually then ?
Thanks for following up!
Best, 

Jade 

Jade Mathilde Sourisse

unread,
Aug 14, 2021, 9:04:25 AM8/14/21
to Bonsai Users
Nevermind I figured that out! Thank you it seems to work so far !
Reply all
Reply to author
Forward
0 new messages