[Python] Style file not found in the style library and input is not a valid URL or path, when...

Discussão em 'Python' iniciado por Stack, Agosto 14, 2025.

  1. Stack

    Stack Membro Participativo

    I have a customized matplotlib style file, called "mystyle.mplstyle".

    In the same folder, I have test.py with the following code:

    import matplotlib.pyplot as plt
    plt.style.use('mystyle.mplstyle')


    That test.py file runs fine.

    But if in a second test2.py file in the same folder, I run the following code:

    import test


    It would generate the following error messages:


    Traceback (most recent call last):
    File "C:/Users/.../test2.py", line 1, in
    import test
    File "C:\Users...\test.py", line 3, in
    plt.style.use('mystyle.mplstyle')
    File "C:\ProgramData\Anaconda3\envs...\lib\site-packages\matplotlib\style\core.py", line 130, in use
    raise IOError( OSError: 'mystyle.mplstyle' not found in the style library and input is not a valid URL or path; see style.available for list of available styles
    ​

    Why is that? How to fix the import?

    Many thanks!!

    Continue reading...

Compartilhe esta Página