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

Mit*_*ril 8 python pip anaconda python-packaging

今天去修改matplotlib的配置。搜索matplotlibrc显示我有两个:

搜索结果截图,有两个条目:<code>C:\Anaconda3\Lib\site-packages\~-tplotlib\mpl-data</code> 和 <code>C:\Anaconda3\Lib\site-packages\matplotlib \mpl-数据</code>

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

Windows 资源管理器屏幕截图显示 site-packages 包含许多其他以 <code>~</code> 符号开头的文件夹,例如 <code>~klearn</code> 和 <code>~yximport</code>

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

这些波浪号名称包的用途是什么?我可以安全地删除它们吗?

Leo*_*Leo 7

您是否有可能使用 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"

    ...
Run Code Online (Sandbox Code Playgroud)

如果这就是这些文件,那么您可以安全地删除它们。