简体   繁体   English

使用 MSYS MinGW 64 安装 matplotlib 为 Python

[英]Install matplotlib for Python with MSYS MinGW 64

I want to install matplotlib for Python using MSYS MinGW x64.我想使用 MSYS MinGW x64 为 Python 安装 matplotlib。 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或者还有另一种方法可以使用 MSYS MinGW x64 安装 matplotlib

I managed to solve the problem by writing a small Java programm that would delete all those files that were cached.我设法通过编写一个小的 Java 程序来解决这个问题,该程序将删除所有缓存的文件。 After that deletion, matplotlib could be successfully installed by pacman and is working now fine.删除之后,pacman 可以成功安装 matplotlib 并且现在可以正常工作。 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.我将问题中的 MSYS2 的 output 保存到文件 filesToDelete.txt 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM