Anaconda/Python网站包中带有波浪号的子文件夹 - 它们是什么?

15

今天,我去更改matplotlib的配置。搜索matplotlibrc发现我有两个:

Screenshot of search results, with two entries: <code>C:\Anaconda3\Lib\site-packages\~-tplotlib\mpl-data</code> and <code>C:\Anaconda3\Lib\site-packages\matplotlib\mpl-data</code>

查看site-packages文件夹,我发现很多软件包的名称中都有波浪线:

Windows Explorer screenshot showing that site-packages contains many other folders starting with a <code>~</code> symbol, like <code>~klearn</code> and <code>~yximport</code>

  • ~klearnsklearn,但还有另一个sklearn
  • ~atplotlib也是matplotlib,更改日期为2018-11
  • ~-tplotlib的更改日期为2019-3.15
  • matplotlib的更改日期为2019-3.28(我最近更新了matplotlib)

这些带波浪符的包有什么用?我能安全地删除它们吗?


3
在Windows约定中,以~开头的目录/文件通常是备份。不确定anaconda是否也是如此。您可以尝试将这些目录剪切并粘贴到另一个目录中,看看是否一切正常运行。 - Ignatius
1
@Taegyung 已经测试过了,删除后一切正常。但是不应该像这样保留旧的包。我担心它们可能有其他用途。 - Mithril
1
您可以使用 conda clean --all --dry-run 进行检查。 - darthbith
有没有办法也执行 pip clean 命令? - studioj
1个回答

19

你是否可能使用pip安装了这些特定的软件包?如果是这样,那么被破坏的目录可能就是pip在卸载软件包(或在卸载软件包以准备更新软件包时)创建的临时目录。

我查阅了pip源代码,发现这段片段显然仅用于卸载软件包时:

class AdjacentTempDirectory(TempDirectory):
    """Helper class that creates a temporary directory adjacent to a real one.
    Attributes:
        original
            The original directory to create a temp directory for.
        path
            After calling create() or entering, contains the full
            path to the temporary directory.
        delete
            Whether the directory should be deleted when exiting
            (when used as a contextmanager)
    """
    # The characters that may be used to name the temp directory
    # We always prepend a ~ and then rotate through these until
    # a usable name is found.
    # pkg_resources raises a different error for .dist-info folder
    # with leading '-' and invalid metadata
    LEADING_CHARS = "-~.=%0123456789"

    ...

如果这些文件确实是那样的话,那么您可以安全地将它们删除。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接