Allen Cell Discussion Forum

Opening segmentation .py files in python

Hi all,

I’ve successfully been running the segmentation through the jupyter notebooks for individual image files.

I now am attempting to loop files through the .py files in either the anaconda prompt (anaconda 3) or python3.8. When I attempt to open the files, python3.8 opens up briefly and immediately closes. If I open python and drag the files in, I get the error message:

File “”, line 1
C:\Users\elcid\aics-segmentation\aicssegmentation\structure_wrapper\seg_ctnnb1.py
^
SyntaxError: unexpected character after line continuation character

Has anyone run into this issue and have a fix?

Thanks,
Aidan

The character \ has a special meaning in python that can cause issues when trying to open files in Windows. It’s been some time since I tried to use python on Windows, so I don’t remember exactly how I got it to work, but you might need to add another \ after each \ and put the filepath in quotations to get it to work properly, like so:
"C:\\Users\\elcid\\aics-segmentation\\aicssegmentation\\structure_wrapper\\seg_ctnnb1.py"

Hi Lynn,

Thanks for your response. Unfortunately I still get the same out come (quickly opening and closing window), with different permutations of quotes and double \. I’ll keep searching for a fix and update if I find something.

Cheers,
Aidan

Hi Aiden,

Could you specify which file are you trying to run and quick open and close?

Thanks,
Jianxu

Hi Jianxu,

I am currently trying to open any of the segmentation files in the structure_wrapper folder (e.g., seg_atp2at.py, seg_cetn2.py, etc…). I modified the segmentation parameters in the cetn2 notebook and would like to run as a loop in the anacando prompt, but as mentioned, cannot seem to actually open the files.

Thanks,
Aidan

Thanks for the clarification. What code editor are you using? Common ones are like VS Code, Atom, Sublime, etc… In any of the code editors, if you simply drag and drop the file into the edit, you will be able to view and edit them, such as seg_cetn2.py or seg_template.py.

Would this help?

Jianxu

Hi Jianxu,

That is a great idea. For the Allen Institute segmentation work I’ve only been using the Anaconda prompt and jupyter notebook.

I am able to drag the .py files into the Spyder IDE which it did indeed show the entire code! I suppose I can now install all the required packages required to run the allen code and hopefully this should allow for the looping of multiple images.

Best,
Aidan

Great to hear~ I hope this demo will be helpful: https://github.com/AllenInstitute/aics-ml-segmentation/blob/master/docs/demo_1.md

Let me know if there is anything I can help clarify
Jianxu