I always get a notification that: Ubuntu faced an internal error. After checking it turn out there is a package not fully installed or removed libapache2-mod-wsgi-py3.

When I run: sudo apt-get upgrade I get:

dpkg: error processing package libapache2-mod-wsgi-py3 (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)

I tried to use sudo apt autoremove. But did not fully remove it I also did: sudo dpkg --remove libapache-mod-wsgi-py3 When I try to remove the package I get this:

dpkg: warning: ignoring request to remove libapache-mod-wsgi-py3 which isn't installed

But still having the same error. How to fix this??

  • Also to my knowledge remove and autoremove do not fully get rid of all files associated w a package..there are multiple locations where related files are stored when you install a package – Hee Jin Apr 26 '18 at 16:09
  • What version(s) of python do you have – Hee Jin Apr 26 '18 at 16:11
  • Thanks @Emily ! Then how to remove all the nested dependencies related to this package? I have Python 2.7, 3.5, and '3.6' – SineCo Apr 26 '18 at 17:43
  • My guess is that there was a conflict with this package and the version of python it was compiled against. What's the output of which python and ps -fA | grep python ? – Hee Jin Apr 26 '18 at 18:34
  • Anyway, since you are having problems removing the package, first I would try using Synaptic to do it. That will take care of alerting you of subpackages that need to be removed as well. Then you could do sudo apt purge (more thorough than remove). If you can't uninstall with synaptic or apt purge, it might be because apache is running and using (or trying to use?) the package...execute sudo systemctl stop apache2.service and then try again – Hee Jin Apr 26 '18 at 18:38

Step 1: Stop apache2 service from running

Before uninstalling enter this command into Terminal/other CLI:

sudo systemctl stop apache2.service

Step 2: Remove package binaries, system-wide configuration files, and orphaned dependencies

To completely remove the package itself, along with its system-wide configuration files and any dependencies that were required by the package but no longer needed, execute:

sudo apt-get purge --auto-remove <packagename>

Explanation: purge does the same thing as apt-get remove --purge; it gets rid of the package itself and associated configuration files. It's like one step above apt-get remove, which only deletes the binaries. --auto-remove does the same thing as apt-get autoremove; it gets rid of orphaned dependencies.

Sorry I didn't give you that specific command to use in the comments, but it's perfectly fine to do everything using separate commands rather than one single command, since the same actions are performed. In your specific case, since you've already done remove --purge, you can just execute the autoremove part now with sudo apt autoremove and that should take care of the stuff that remove --purge didn't delete. The single-entry way is just a bit faster.

Alternatively, if you want to be selective about what dependencies get removed, you can get rid of the --auto-remove flag (executing sudo apt-get purge <packagename>) and follow the steps I found from this amazing answer to easily create a sort of custom dependency-uninstaller. The following command first lists all package dependencies, then pipes that list into individual apt-get remove commands, which all gets sent to a shell script that you can open in a text editor and modify as needed. Then you just execute the shell script once you're happy with it. The command is:

apt-cache depends <packagename>|awk '{print "sudo apt-get remove "$NF}' >pg_remove.sh

The pg_remove.sh file is saved to your home directory (obviously you can add a path before the output file name if you want to save it somewhere else). To run the script execute bash pg_remove.sh (again if your output file is not in your home directory, modify this command to include the path to its location).

Step 3: Remove user configuration files

Next you have to manually remove user-specific configuration files stored in your home directory. These may be in their own directory, and/or in ~/.config, ~/.cache, ~/.local.

First look for files that contain the package name in ~/.config and remove them. You can use ls -a ~/.config or ls -A ~/.config to see all the contents of your home, including hidden files/folders. If you're using Nautilus to do this, make sure you have enabled the option to view hidden files (View>Show Hidden Files). Then delete them using rm or Nautilus.

Also look in your home folder for a directory with the package name (or something that looks like the package name--it may not be exactly the same). It will probably be hidden by default, and it will probably begin with a "."--if it exists. I don't know that much about apache so I'm not sure if this directory will be there, or what it would look like. Anyway, if it exists, remove it also!

Additionally, check in ~/.cache and ~/.local/share for a directory named after the package.

References for Steps 2 and 3: How can you completely remove a package?, What is the correct way to completely remove an application?, How to remove configuration files completely

Possible future reinstallation

This package may have libraries you you actually need in the future and you may need to reinstall it. Ubuntu comes with libapache2-mod-wsgi-py3 installed, which is like a default version, so my guess is that it couldn't play nicely with whatever Python version you were using. If you want to know more check the output of which python and ps -fA | grep python...If a conflict with the Python version was indeed the problem, then this question and this one address how you can properly install mod-wgsi via pip (the package pip installs is something called mod_wgsi).

| improve this answer | |
  • @SineCo, awesome! You're welcome! – Hee Jin Apr 26 '18 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.