[Python] Can't plot after importing torch. Causes crash in Spyder and in command line python...

Discussão em 'Python' iniciado por Stack, Setembro 14, 2024.

  1. Stack

    Stack Membro Participativo

    My code crashes and burns when I try to create a plot after importing torch unless I first plot and then import torch. I'm using windows 11. More specifically:

    The following code runs and plots in freshly loaded spyder:

    import pandas as pd
    df = pd.DataFrame({'length': [1.5, 0.5, 1.2, 0.9, 3],
    'width': [0.7, 0.2, 0.15, 0.2, 1.1]},
    index=['pig', 'rabbit', 'duck', 'chicken', 'horse'])
    plot = df.plot(title="DataFrame Plot"


    As does the following code:

    import pandas as pd

    df = pd.DataFrame({'length': [1.5, 0.5, 1.2, 0.9, 3],
    'width': [0.7, 0.2, 0.15, 0.2, 1.1]},
    index=['pig', 'rabbit', 'duck', 'chicken', 'horse'])
    plot = df.plot(title="DataFrame Plot")


    import torch


    df = pd.DataFrame({'length': [1.5, 5.5, 1.2, 0.9, 3],
    'width': [0.7, 0.2, 0.15, 0.2, 1.1]},
    index=['pig', 'rabbit', 'duck', 'chicken', 'horse'])
    plot = df.plot(title="DataFrame2 Plot")


    However the following code (first plot is commented out) crashes and burns. It causes the kernel to restart in spyder. In this case the plot only comes after importing torch:

    import pandas as pd

    #df = pd.DataFrame({'length': [1.5, 0.5, 1.2, 0.9, 3],
    # 'width': [0.7, 0.2, 0.15, 0.2, 1.1]},
    # index=['pig', 'rabbit', 'duck', 'chicken', 'horse'])
    #plot = df.plot(title="DataFrame Plot")


    import torch


    df = pd.DataFrame({'length': [1.5, 5.5, 1.2, 0.9, 3],
    'width': [0.7, 0.2, 0.15, 0.2, 1.1]},
    index=['pig', 'rabbit', 'duck', 'chicken', 'horse'])
    plot = df.plot(title="DataFrame Plot")


    The error messages are:

    Fatal Python error: Aborted


    Main thread:
    Current thread 0x00003378 (most recent call first):
    File "c:\ProgramData\Anaconda3\Lib\site-packages\matplotlib\transforms.py", line 2436 in get_affine
    File "c:\ProgramData\Anaconda3\Lib\site-packages\matplotlib\transforms.py", line 2409 in transform_affine
    File "c:\ProgramData\Anaconda3\Lib\site-packages\matplotlib\_api\deprecation.py", line 297 in wrapper
    File "c:\ProgramData\Anaconda3\Lib\site-packages\matplotlib\transforms.py", line 1495 in transform
    File "c:\ProgramData\Anaconda3\Lib\site-packages\matplotlib\transforms.py", line 468 in transformed
    File "c:\ProgramData\Anaconda3\Lib\site-packages\matplotlib\axis.py", line 2515 in get_tick_space
    File "c:\ProgramData\Anaconda3\Lib\site-packages\matplotlib\ticker.py", line 2088 in _raw_ticks
    File "c:\ProgramData\Anaconda3\Lib\site-packages\matplotlib\ticker.py", line 2150 in tick_values
    File "c:\ProgramData\Anaconda3\Lib\site-packages\matplotlib\ticker.py", line 2142 in __call__
    File "c:\ProgramData\Anaconda3\Lib\site-packages\matplotlib\axis.py", line 1495 in get_majorticklocs
    File "c:\ProgramData\Anaconda3\Lib\site-packages\matplotlib\axis.py", line 1275 in _update_ticks
    File "c:\ProgramData\Anaconda3\Lib\site-packages\matplotlib\axis.py", line 1424 in get_majorticklabels
    File "c:\ProgramData\Anaconda3\Lib\site-packages\pandas\plotting\_matplotlib\core.py", line 822 in _apply_axis_properties
    File "c:\ProgramData\Anaconda3\Lib\site-packages\pandas\plotting\_matplotlib\core.py", line 720 in _post_plot_logic_common
    File "c:\ProgramData\Anaconda3\Lib\site-packages\pandas\plotting\_matplotlib\core.py", line 507 in generate
    File "c:\ProgramData\Anaconda3\Lib\site-packages\pandas\plotting\_matplotlib\__init__.py", line 71 in plot
    File "c:\ProgramData\Anaconda3\Lib\site-packages\pandas\plotting\_core.py", line 1030 in __call__
    File "c:\users\2733\downloads\createerror.py", line 22 in <module>
    File "c:\ProgramData\Anaconda3\Lib\site-packages\spyder_kernels\py3compat.py", line 356 in compat_exec
    File "c:\ProgramData\Anaconda3\Lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 473 in exec_code
    File "c:\ProgramData\Anaconda3\Lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 615 in _exec_file
    File "c:\ProgramData\Anaconda3\Lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 528 in runfile
    File "C:\Users\2733\AppData\Local\Temp\ipykernel_21156\1765460541.py", line 1 in <module>


    If the code is run in from a command line python (windows 11) The error message is:

    OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
    OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program.
    That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library.
    As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results.
    For more information, please see http://www.intel.com/software/products/support/.

    Continue reading...

Compartilhe esta Página