The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Python
 'NoneType' object is not subscriptable
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cts18488

United Kingdom
82 Posts

Posted - 08/05/2022 :  05:55:01 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 2021b and Service Release (Select Help-->About Origin): SR2
Operating System: Win10 Ent

Hi,

I have a Python-based software that process the data using Origin. I have tried to analyse a file recently, but I have got the following error: " 'NoneType' object is not subscriptable ". This error appears after the data are put in columns and before generating the graphs from the template (the template is 16 panel graphs (4 rows and 4 columns) in which the first graph is hidden). The problem appears when I run the software after it was converted to an executable file (using pyinstaller); it works well when run from Visual Studio Code. Furthermore, when I have tried to analyse the data (from an .exe generated by pyinstaller) but this time using a similar template (but the first graph is not hidden) the processing worked well.

I would appreciate any help/ideas how to overcome this.

Thank you,
Tibi

minimax

348 Posts

Posted - 08/08/2022 :  04:56:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Would you mind to show the context py scripts which dump the error msg, so that we can check in details?
Go to Top of Page

cts18488

United Kingdom
82 Posts

Posted - 08/18/2022 :  05:21:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

This is the code that I am using - it is a bit long:

                            def origin_shutdown_exception_hook(exctype, value, traceback):
                                '''Ensures Origin gets shut down if an uncaught exception'''
                                op.exit()
                                sys.__excepthook__(exctype, value, traceback)
                            if op and op.oext:
                                sys.excepthook = origin_shutdown_exception_hook

                            if op.oext:
                                op.set_show(True)

                            wks = op.new_sheet(lname = f'16MM {session_name2}') # for normal plots
                            wks.name = 'M00'

                            wks.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks.from_list(1, M00_list[0], lname='M00', comments='M00')
                            wks_M01 = wks.get_book().add_sheet('M01')   
                            wks_M01.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks_M01.from_list(1, M01_list[0], lname='M01', comments='M01')
                            wks_M02 = wks.get_book().add_sheet('M02')   
                            wks_M02.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks_M02.from_list(1, M02_list[0], lname='M02', comments='M02')
                            wks_M03 = wks.get_book().add_sheet('M03')   
                            wks_M03.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks_M03.from_list(1, M03_list[0], lname='M03', comments='M03')
                            wks_M10 = wks.get_book().add_sheet('M10')   
                            wks_M10.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks_M10.from_list(1, M10_list[0], lname='M10', comments='M10')
                            wks_M11 = wks.get_book().add_sheet('M11')   
                            wks_M11.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks_M11.from_list(1, M11_list[0], lname='M11', comments='M11')
                            wks_M12 = wks.get_book().add_sheet('M12')   
                            wks_M12.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks_M12.from_list(1, M12_list[0], lname='M12', comments='M12')
                            wks_M13 = wks.get_book().add_sheet('M13')   
                            wks_M13.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks_M13.from_list(1, M13_list[0], lname='M13', comments='M13')
                            wks_M20 = wks.get_book().add_sheet('M20')   
                            wks_M20.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks_M20.from_list(1, M20_list[0], lname='M20', comments='M20')
                            wks_M21 = wks.get_book().add_sheet('M21')   
                            wks_M21.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks_M21.from_list(1, M21_list[0], lname='M21', comments='M21')
                            wks_M22 = wks.get_book().add_sheet('M22')   
                            wks_M22.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks_M22.from_list(1, M22_list[0], lname='M22', comments='M22')
                            wks_M23 = wks.get_book().add_sheet('M23')   
                            wks_M23.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks_M23.from_list(1, M23_list[0], lname='M23', comments='M23')
                            wks_M30 = wks.get_book().add_sheet('M30')  
                            wks_M30.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks_M30.from_list(1, M30_list[0], lname='M30', comments='M30')
                            wks_M31 = wks.get_book().add_sheet('M31')   
                            wks_M31.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks_M31.from_list(1, M31_list[0], lname='M31', comments='M31')
                            wks_M32 = wks.get_book().add_sheet('M32')   
                            wks_M32.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks_M32.from_list(1, M32_list[0], lname='M32', comments='M32')
                            wks_M33 = wks.get_book().add_sheet('M33')   
                            wks_M33.from_list(0, Wavelength_new, lname='Wavelength', units='nm')
                            wks_M33.from_list(1, M33_list[0], lname='M33', comments='M33')


                            if len(M00_list) > 1:
                                for i in range(1, len(M00_list)):
                                    wks.from_list(i+1, M00_list)
                                    wks_M01.from_list(i+1, M01_list[i])
                                    wks_M02.from_list(i+1, M02_list[i])
                                    wks_M03.from_list(i+1, M03_list[i])
                                    wks_M10.from_list(i+1, M10_list[i])
                                    wks_M11.from_list(i+1, M11_list[i])
                                    wks_M12.from_list(i+1, M12_list[i])
                                    wks_M13.from_list(i+1, M13_list[i])
                                    wks_M20.from_list(i+1, M20_list[i])
                                    wks_M21.from_list(i+1, M21_list[i])
                                    wks_M22.from_list(i+1, M22_list[i])
                                    wks_M23.from_list(i+1, M23_list[i])
                                    wks_M30.from_list(i+1, M30_list[i])
                                    wks_M31.from_list(i+1, M31_list[i])
                                    wks_M32.from_list(i+1, M32_list[i])
                                    wks_M33.from_list(i+1, M33_list[i])

                            path_template = os.getcwd()

                            new_path_template = path_template.replace('/', '\\')

                            gr = op.new_graph(template=(new_path_template + '\\Origin templates\\test_plot16 - normalisation.otpu'), lname=f'16MM plot{session_name2}')

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M00'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_1 = gr[0]
                            p1 = gl_1.add_plot(f'{wks.lt_range()}!(?,1:end)')
                            p1.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_1.set_int("x.AtZero",1)
                            gl_1.group()
                            p1.colormap = 'Candy'
                            gl_1.rescale()
                            gl_1.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M00 = gr[0].label('Legend')
                            lgnd_M00.text = ' %(1)'

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M01'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_2 = gr[1]
                            p2 = gl_2.add_plot(f'{wks_M01.lt_range()}!(?,1:end)')
                            p2.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_1.set_int("x.AtZero",1)
                            gl_2.group()
                            p2.colormap = 'Candy'
                            gl_2.rescale()
                            gl_2.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M01 = gr[1].label('Legend')
                            lgnd_M01.text = ' %(1)'

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M02'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_3 = gr[2]
                            p3 = gl_3.add_plot(f'{wks_M02.lt_range()}!(?,1:end)')
                            p3.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_3.set_int("x.AtZero",1)
                            gl_3.group()
                            p3.colormap = 'Candy'
                            gl_3.rescale()
                            gl_3.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M02 = gr[2].label('Legend')
                            lgnd_M02.text = ' %(1)'

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M03'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_4 = gr[3]
                            p4 = gl_4.add_plot(f'{wks_M03.lt_range()}!(?,1:end)')
                            p4.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_4.set_int("x.AtZero",1)
                            gl_4.group()
                            p4.colormap = 'Candy'
                            gl_4.rescale()
                            gl_4.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M03 = gr[3].label('Legend')
                            lgnd_M03.text = ' %(1)'

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M10'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_5 = gr[4]
                            p5 = gl_5.add_plot(f'{wks_M10.lt_range()}!(?,1:end)')
                            p5.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_5.set_int("x.AtZero",1)
                            gl_5.group()
                            p5.colormap = 'Candy'
                            gl_5.rescale()
                            gl_5.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M10 = gr[4].label('Legend')
                            lgnd_M10.text = ' %(1)'

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M11'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_6 = gr[5]
                            p6 = gl_6.add_plot(f'{wks_M11.lt_range()}!(?,1:end)')
                            p6.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_6.set_int("x.AtZero",1)
                            gl_6.group()
                            p6.colormap = 'Candy'
                            gl_6.rescale()
                            gl_6.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M11 = gr[5].label('Legend')
                            lgnd_M11.text = ' %(1)'

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M12'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_7 = gr[6]
                            p7 = gl_7.add_plot(f'{wks_M12.lt_range()}!(?,1:end)')
                            p7.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_7.set_int("x.AtZero",1)
                            gl_7.group()
                            p7.colormap = 'Candy'
                            gl_7.rescale()
                            gl_7.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M12 = gr[6].label('Legend')
                            lgnd_M12.text = ' %(1)'

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M13'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_8 = gr[7]
                            p8 = gl_8.add_plot(f'{wks_M13.lt_range()}!(?,1:end)')
                            p8.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_8.set_int("x.AtZero",1)
                            gl_8.group()
                            p8.colormap = 'Candy'
                            gl_8.rescale()
                            gl_8.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M13 = gr[7].label('Legend')
                            lgnd_M13.text = ' %(1)'

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M20'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_9 = gr
                            p9 = gl_9.add_plot(f'{wks_M20.lt_range()}!(?,1:end)')
                            p9.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_9.set_int("x.AtZero",1)
                            gl_9.group()
                            p9.colormap = 'Candy'
                            gl_9.rescale()
                            gl_9.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M20 = gr.label('Legend')
                            lgnd_M20.text = ' %(1)'

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M21'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_10 = gr[9]
                            p10 = gl_10.add_plot(f'{wks_M21.lt_range()}!(?,1:end)')
                            p10.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_10.set_int("x.AtZero",1)
                            gl_10.group()
                            p10.colormap = 'Candy'
                            gl_10.rescale()
                            gl_10.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M21 = gr[9].label('Legend')
                            lgnd_M21.text = ' %(1)'

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M22'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_11 = gr[10]
                            p11 = gl_11.add_plot(f'{wks_M22.lt_range()}!(?,1:end)')
                            p11.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_11.set_int("x.AtZero",1)
                            gl_11.group()
                            p11.colormap = 'Candy'
                            gl_11.rescale()
                            gl_11.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M22 = gr[10].label('Legend')
                            lgnd_M22.text = ' %(1)'

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M23'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_12 = gr[11]
                            p12 = gl_12.add_plot(f'{wks_M23.lt_range()}!(?,1:end)')
                            p12.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_12.set_int("x.AtZero",1)
                            gl_12.group()
                            p12.colormap = 'Candy'
                            gl_12.rescale()
                            gl_12.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M23 = gr[11].label('Legend')
                            lgnd_M23.text = ' %(1)'

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M30'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_13 = gr[12]
                            p13 = gl_13.add_plot(f'{wks_M30.lt_range()}!(?,1:end)')
                            p13.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_13.set_int("x.AtZero",1)
                            gl_13.group()
                            p13.colormap = 'Candy'
                            gl_13.rescale()
                            gl_13.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M30 = gr[12].label('Legend')
                            lgnd_M30.text = ' %(1)'

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M31'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_14 = gr[13]
                            p14 = gl_14.add_plot(f'{wks_M31.lt_range()}!(?,1:end)')
                            p14.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_14.set_int("x.AtZero",1)
                            gl_14.group()
                            p14.colormap = 'Candy'
                            gl_14.rescale()
                            gl_14.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M31 = gr[13].label('Legend')
                            lgnd_M31.text = ' %(1)'

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M32'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_15 = gr[14]
                            p15 = gl_15.add_plot(f'{wks_M32.lt_range()}!(?,1:end)')
                            p15.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_15.set_int("x.AtZero",1)
                            gl_15.group()
                            p15.colormap = 'Candy'
                            gl_15.rescale()
                            gl_15.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M32 = gr[14].label('Legend')
                            lgnd_M32.text = ' %(1)'

                            poz = 0
                            neg = 0

                            for i in range(len(csv_file)):
                                if csv_file['M33'][i] > 0:
                                    poz = poz + 1
                                else:
                                    neg = neg + 1

                            gl_16 = gr[15]
                            p16 = gl_16.add_plot(f'{wks_M33.lt_range()}!(?,1:end)')
                            p16.set_int('line.width', 3)
                            if (neg >= 1) and poz >=1:
                                gl_16.set_int("x.AtZero",1)
                            gl_16.group()
                            p16.colormap = 'Candy'
                            gl_16.rescale()
                            gl_16.xlim = (min(csv_file['Wavelength']), max(csv_file['Wavelength']))
                            lgnd_M33 = gr[15].label('Legend')
                            lgnd_M33.text = ' %(1)'

                            if op.oext:
                                op.exit()

quote:
[i]Originally posted by minimax


Would you mind to show the context py scripts which dump the error msg, so that we can check in details?


Edited by - cts18488 on 08/18/2022 10:33:23 AM
Go to Top of Page

minimax

348 Posts

Posted - 08/18/2022 :  05:44:03 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Would you mind to modify your original post and paste the script inside [code] block? (you can click the # button in the Format bar to add a code block)

It can help to keep the indent and easier to read.


Go to Top of Page

cts18488

United Kingdom
82 Posts

Posted - 08/18/2022 :  10:34:23 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Done. I have updated the post as requested. I didn't know that feature exists.
quote:
Originally posted by minimax

Hi,

Would you mind to modify your original post and paste the script inside [code] block? (you can click the # button in the Format bar to add a code block)

It can help to keep the indent and easier to read.




Go to Top of Page

minimax

348 Posts

Posted - 08/18/2022 :  10:56:08 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Tibi,

We guess the problem is on line
path_template = os.getcwd()


It probably does not return a same value as from Visual Studio Code.

You can add script print(path_template) to verify it.

If yes, you may need some other script to make sure it returns the correct path for both exe and py.

If it is not the case, would you mind to paste the full error messages? like
Traceback (most recent call last):
  File "pathtest.py", line 28, in <module>
    gl1=gp[0]
TypeError: 'NoneType' object is not subscriptable
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000