Python3 uninstall error: externally-managed-environment

Python 3 Uninstall Error: Externally Managed Environment

Python 3 Uninstall Error: Externally Managed Environment

When using Python 3, you may sometimes encounter strange errors. One common issue is encountering an “externally managed environment” error when uninstalling Python 3. This error occurs because the Python 3 uninstallation process does not completely remove all related files and dependencies, preventing the system from being cleaned up. This article will explain the causes and solutions of this error in detail.

Problem Description

When trying to uninstall Python 3 through the command line, you may encounter an error message similar to the following:

$ sudo apt-get remove python3
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'python3' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove, and 88 not upgraded.
0 upgraded, 0 newly installed, 0 to remove, and 88 not upgraded.
python3
Externally-managed environment

This error message indicates that Python 3 was not successfully removed and is shown as being managed in an “Externally-managed environment.” This may be caused by previously installing Python 3 manually or through other means.

Cause of the Error

The “Externally-managed environment” error occurs because the system has recorded the Python 3 installation path and dependency information, but this information was not properly cleared during the Python 3 uninstallation. As a result, the system cannot recognize the Python 3 installation, preventing a complete uninstallation.

Solution

To resolve the “Externally-managed environment” error, manually clean up any remaining Python 3 files and dependency information on the system. Here are some possible solutions:

1. Manually remove the Python 3 installation files
First, we can manually remove the Python 3 installation files and directories using the following commands:
$ sudo rm -rf /usr/bin/python3
$ sudo rm -rf /usr/local/lib/python3.6
$ sudo rm -rf /usr/local/lib/python3.7
$ sudo rm -rf /usr/lib/python3

Please note that you should modify the Python 3 version number in the above commands to match the Python 3 version on your system. After executing these commands, the Python 3 installation files and directories on your system will be completely removed.

2. Remove Python 3 Dependencies
In addition to removing the Python 3 installation files, we also need to remove Python 3’s dependencies. You can find and remove Python 3 dependencies using the following command:

$ dpkg -l | grep python3
$ sudo apt-get autoremove python3

The above command will list all Python 3-related packages on your system and automatically remove any that are no longer needed. After executing these commands, all Python 3 dependencies will be removed from your system.

3. Reinstall Using the Python 3 Installation Package

If the above method still doesn’t resolve the issue, you can try reinstalling Python 3 and then uninstalling it. This will overwrite the previous installation and resolve the “Externally managed environment” error.

You can reinstall Python 3 using the following command:

$ sudo apt-get install python3

After the installation is complete, try uninstalling Python 3 using the following command:

$ sudo apt-get remove python3

This should successfully uninstall Python 3 and avoid the “Externally-managed environment” error.

Conclusion

The “Externally-managed environment” error is a common problem you may encounter when uninstalling Python 3. It’s usually caused by the system failing to properly clean up Python 3’s installation files and dependencies. You can resolve this error by manually cleaning up Python 3’s installation files and dependencies, or by reinstalling Python 3 and then uninstalling it.

Leave a Reply

Your email address will not be published. Required fields are marked *