Search code examples
pythonpippackage

Get list of latest installed python packages


I am trying to get an ordered list of the lastest installed packages in Python. I am using pip (I cannot use -conda or terminal). The instruction pip list returns all the packages I have ever installed. Since I installed a package which damaged the older ones, I need the list of the latest installed packages in order to uninstall only them and reinstall them later. In simple words, I need to do a rollback. How can I do it?


Solution

  • You can list the packages, with:

    import pkg_resources
    import os
    import time
    
    for package in pkg_resources.working_set:
        print(f'{package}\n, Installed: {time.ctime(os.path.getctime(package.location))}')