How do I remove debian packages using python apt API
<p>I'm was trying this on Linux mint. I have been researching on how to remove packages using the python-apt API. The piece of code below was all I could come up with but nothing happens when I run it. I am trying to remove a single package right now but later I would like to remove a list of packages from a text file. I tried to use the answer found in <a href="https://stackoverflow.com/questions/17537390/how-to-install-a-package-using-the-python-apt-api">this post</a> and re-engineered it for removing but my logic does not work. Please give me some input.</p>

<pre><code>#!/usr/bin/env python
# aptuninnstall.py

import apt
import sys


def remove():
    pkg_name = "chromium-browser"
    cache = apt.cache.Cache()
    cache.update()
    pkg = cache[pkg_name]
    pkg.marked_delete
    resolver = apt.cache.ProblemResolver(cache)
    for pkg in cache.get_changes():
        if pkg.is_installed:
            resolver.remove(pkg)
        else:
            print (pkg_name + " not installed so not removed")
    try:
        cache.commit()
    except Exception, arg:
        print &gt;&gt; sys.stderr, "Sorry, package removal failed [{err}]".format(err=str(arg))

remove()
</code></pre>