Install matplotlib for Python with MSYS MinGW 64

362 Views Asked by At

I want to install matplotlib for Python using MSYS MinGW x64. The command

$ pacman -S mingw-w64-x86_64-python-matplotlib

had failed previously. Then I made some changes, and now I want to try the above command again, but I only get these error messages:

$ pacman -S mingw-w64-x86_64-python-matplotlib
resolving dependencies...
looking for conflicting packages...

Packages (12) mingw-w64-x86_64-libimagequant-4.0.4-2  mingw-w64-x86_64-libraqm-0.9.0-1
              mingw-w64-x86_64-python-cycler-0.11.0-2  mingw-w64-x86_64-python-dateutil-2.8.2-3
              mingw-w64-x86_64-python-fonttools-4.38.0-1  mingw-w64-x86_64-python-packaging-22.0-1
              mingw-w64-x86_64-python-pillow-9.3.0-2  mingw-w64-x86_64-python-pyparsing-3.0.9-3
              mingw-w64-x86_64-python-pytz-2022.7-1  mingw-w64-x86_64-python-six-1.16.0-3
              mingw-w64-x86_64-qhull-2020.2-2  mingw-w64-x86_64-python-matplotlib-3.6.2-1

Total Installed Size:  60.64 MiB

:: Proceed with installation? [Y/n] Y

imelf@DESKTOP-CFHKUQA MINGW64 ~
$ pacman -S mingw-w64-x86_64-python-matplotlib
resolving dependencies...
looking for conflicting packages...

Packages (12) mingw-w64-x86_64-libimagequant-4.0.4-2  mingw-w64-x86_64-libraqm-0.9.0-1
              mingw-w64-x86_64-python-cycler-0.11.0-2  mingw-w64-x86_64-python-dateutil-2.8.2-3
              mingw-w64-x86_64-python-fonttools-4.38.0-1  mingw-w64-x86_64-python-packaging-22.0-1
              mingw-w64-x86_64-python-pillow-9.3.0-2  mingw-w64-x86_64-python-pyparsing-3.0.9-3
              mingw-w64-x86_64-python-pytz-2022.7-1  mingw-w64-x86_64-python-six-1.16.0-3
              mingw-w64-x86_64-qhull-2020.2-2  mingw-w64-x86_64-python-matplotlib-3.6.2-1

Total Installed Size:  60.64 MiB

:: Proceed with installation? [Y/n] Y
(12/12) checking keys in keyring                             [###############################] 100%
(12/12) checking package integrity                           [###############################] 100%
(12/12) loading package files                                [###############################] 100%
(12/12) checking for file conflicts                          [###############################] 100%
error: failed to commit transaction (conflicting files)
mingw-w64-x86_64-python-six: /mingw64/lib/python3.10/site-packages/__pycache__/six.cpython-310.pyc exists in filesystem
mingw-w64-x86_64-python-six: /mingw64/lib/python3.10/site-packages/six.py exists in filesystem
mingw-w64-x86_64-python-cycler: /mingw64/lib/python3.10/site-packages/__pycache__/cycler.cpython-310.pyc exists in filesystem
mingw-w64-x86_64-python-cycler: /mingw64/lib/python3.10/site-packages/cycler.py exists in filesystem
mingw-w64-x86_64-python-dateutil: /mingw64/lib/python3.10/site-packages/dateutil/__init__.py exists in filesystem
mingw-w64-x86_64-python-dateutil: /mingw64/lib/python3.10/site-packages/dateutil/__pycache__/__init__.cpython-310.pyc exists in filesystem
mingw-w64-x86_64-python-dateutil: /mingw64/lib/python3.10/site-packages/dateutil/__pycache__/_common.cpython-310.pyc exists in filesystem
mingw-w64-x86_64-python-dateutil: /mingw64/lib/python3.10/site-packages/dateutil/__pycache__/_version.cpython-310.pyc exists in filesystem
mingw-w64-x86_64-python-dateutil: /mingw64/lib/python3.10/site-packages/dateutil/__pycache__/easter.cpython-310.pyc exists in filesystem

My question: How can I delete the cached files, so I get meaningful error messages again. Or is there another way to install matplotlib with MSYS MinGW x64

1

There are 1 best solutions below

0
On

I managed to solve the problem by writing a small Java programm that would delete all those files that were cached. After that deletion, matplotlib could be successfully installed by pacman and is working now fine. Here is my code:

    package msys2cachedeleter;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    private static final String pattern1 = "(/mingw64/bin/(fonttools|pyftmerge|pyftsubset|ttx)\\.exe) exists in filesystem";
    private static final String pattern2 = "(/mingw64/lib/python3\\.10/site-packages/(.+?))\\s+exists in filesystem";
    
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        
        deleteFilesMatchingPattern(pattern1, "filesToDelete2.txt");
        deleteFilesMatchingPattern(pattern2, "filesToDelete.txt");
    }

    private static void deleteFilesMatchingPattern(String pattern, String filesToDelete) throws IOException {
        Pattern p = Pattern.compile(pattern);
        
        Path filePath = Path.of(filesToDelete);

        String content = Files.readString(filePath);
        
        Matcher m = p.matcher(content);
        
        while(m.find() ) {
            File f = new File("D:/Software/MSYS2" + m.group(1) );
            if( f.exists() ) {
                System.out.println("The file " + m.group(1) + " does indeed exist");
            }
            else {
                System.out.println("The file " + m.group(1) + " doesn't exist");
            }
            
            
            if( f.delete()) {
                System.out.println("The file could be deleted!");
            }
            else {
                System.out.println("It couldn't be deleted");
            }
            
            
        }
    }

}

where I saved the output of MSYS2 from the question to the files filesToDelete.txt.