Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anaconda/Python site-packages subfolders with tilde in name - what are they?

Today, I went to change the config of matplotlib. Searching matplotlibrc revealed I have two of them:

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>

Looking at the site-packages folder, I found a lot of packages have a tilde in their name:

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>

  • ~klearn is sklearn , but there is another sklearn .
  • ~atplotlib is matplotlib too, changed date is 2018-11
  • ~-tplotlib's changed date is 2019-3.15
  • matplotlib's changed date is 2019-3.28 (I did update matplotlib recently)

What are these tilde name packages used for? Can I delete them safely?

like image 593
Mithril Avatar asked Apr 08 '19 03:04

Mithril


People also ask

What are python site-packages?

site-packages is the target directory of manually built Python packages. When you build and install Python packages from source (using distutils, probably by executing python setup.py install ), you will find the installed modules in site-packages by default.

Where are Anaconda site-packages?

The answer is the site-packages in the sys. path list.

Where does conda store Python packages?

Conda installs packages into the anaconda/pkgs directory. If conda cannot find the file, try using an absolute path name instead of a relative path name. Installing packages directly from the file does not resolve dependencies.

Where are Python modules installed Windows?

Locally installed Python and all packages will be installed under a directory similar to ~/. local/bin/ for a Unix-based system, or \Users\Username\AppData\Local\Programs\ for Windows.


1 Answers

Is it possible that you installed those particular packages with pip? If so, then the mangled directories are probably the temporary directories that pip creates when it uninstalls a package (or when it uninstalls a package in preparation for updating a package).

I dug through the pip source code and found this snippet which is evidently only used on uninstalling packages:

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"

    ...

If that's what these files are, then you can safely delete them.

like image 183
Leo Avatar answered Oct 12 '22 09:10

Leo