Search code examples
pythonpython-3.xpip

Uninstall last pip installed packages


I have just installed a package in my virtual environment which I shouldn't have installed. It also installed many dependency packages.

Is there a way to roll back and uninstall the package and its dependencies just installed?

Something like "uninstall packages installed in the last 1 hour" or a similar functionality.


Solution

  • Below snippet can help you identify the recently installed pacakage. Once you have the list of packages, you can manually uninstall that pacakge.

    import pkg_resources
    import os
    import time
    
    for package in pkg_resources.working_set:
        print("%s: %s" % (package, time.ctime(os.path.getctime(package.location))))