Uninstall python installed from source

The following commands will remove your make altinstall-ed python:

rm -f /usr/local/bin/python2.7
rm -f /usr/local/bin/pip2.7
rm -f /usr/local/bin/pydoc
rm -rf /usr/local/bin/include/python2.7
rm -f /usr/local/lib/libpython2.7.a
rm -rf /usr/local/lib/python2.7

You might also have to do

rm -f /usr/local/share/man/python2.7.1
rm -rf /usr/local/lib/pkgconfig
rm -f /usr/local/bin/idle
rm -f /usr/local/bin/easy_install-2.7

Although make altinstall has served me well if the "system python" has a different major.minor number from the one you install, it doesn't work that well if only the micro number [the third position] differs. That number is excluded from the installed binary, and you end up with two versions pythonX.Y. This was always a problem but once distributions started shipping with system utilities based on 2.7.X this problem has been more severe as 2.7 is supposed to be the last of the Python2 series.

IMO the best approach to solve this problem is to prevent it from becoming one: configure python to install in a directory not used by any other python. On my system they go under /opt/python/X.Y.Z.

To use any of the Pythons installed there you use [virualenv][1] to make a new environment:

virtualenv --python=/opt/python/2.7.9/bin/python2.7 venv
source venv/bin/activate

or use [virtualenvwrapper][2]. I have some aliases for the latest versions in the series I work with.

If you are using tox for testing against multiple versions [you should] the following alias will help it find the various version:

alias tox='PATH=/opt/python/2.7.9/bin:/opt/python/2.6.9/bin:/opt/python/3.4.3/bin:/opt/python/3.3.6/bin:/opt/python/3.5-dev/bin:$PATH tox'

[these are currently the latest versions, I use a slightly different setup by maintaining links from /opt/python/2.7 to the latest /opt/python/2.7.9, and for the other minor numbers as well, within the process for downloading, building and installing a new python version]

These installs are never used directly. They are always used as the basis for virtualenv environments only, hence I don't care that they are not in my normal PATH.

All Python package management solutions provide the basic function of uninstalling packages, including pip, pipenv and the ActiveState Platform. However, unless specifically defined in a requirements.txt or pipfile.lock, package managers will not deal with transitive dependencies [ie., dependencies of dependencies].

In this article, we explain how to uninstall Python packages using these popular tools and we also introduce you to the ActiveState Platform. The AS Platform is unique in automatically installing and uninstalling transitive dependencies. Our dependency management system makes it possible to track conflicts between packages, know about platform-specific dependencies, and even track system-level dependencies like C and C++ libraries. Once you are done reading, you can try the ActiveState Platform by signing up for a free account.

Read on to understand how to work with Pip and Pipenv Package Managers to uninstall Python packages.

Checklist

Before packages can be uninstalled, ensure that a Python installation containing the necessary files needed for uninstalling packages is in place. Installation Requirements [for Windows].

How to Uninstall Packages Installed with Pip

To uninstall a package: 

pip uninstall 

How to Uninstall Packages in a Python Virtual Environment

Packages can be uninstalled from a virtual environment using pip or pipenv. 

To use pip to uninstall a package locally in a virtual environment:

  1. Open a command or terminal window [depending on the operating system] 
  2. cd into the project directory
  3. pip uninstall

To use pipenv to uninstall a package locally in a virtual environment created with venv or virtualenv:

  1. Open a command or terminal window [depending on the operating system] 
  2. cd into the project directory
  3. pipenv uninstall

How to Globally Uninstall Python Packages

In some cases, packages may be installed both locally [e.g., for use in a specific project] and system-wide. To ensure a package is completely removed from your system after you’ve uninstalled it locally, you’ll also need to uninstall it globally.

To uninstall a package globally in Windows: 

    1. Open a command window by entering ‘cmd’ in the Search Box of the Task bar
    2. Press Ctrl+Shift+Enter to gain Administration [Admin] privileges
    3. pip uninstall

To uninstall a package globally in Linux:

    1. Open a terminal window
    2. sudo su pip uninstall

How to Uninstall Package Dependencies with Pip

When you install a package with pip, it also installs all of the dependencies the package requires. Unfortunately, pip does not uninstall dependencies when you uninstall the original package. Here are a couple of different procedures that can be used to uninstall dependencies.

  1. If a package has been installed via a pip requirements file [i.e., pip install requirements.txt], all of the packages in requirements.txt can be uninstalled with the following command:
pip uninstall requirements.txt
  1. If a requirements.txt file is not available, you can use the pip show command to output all the requirements of a specified package:
pip show 

Example:

pip show cryptography

Output should be similar to: 

'Requires: six, cffi'

These dependencies can then be uninstalled with the pip uninstall command. However before uninstalling, you should ensure that the packages are NOT dependencies for other existing packages.

How to Uninstall Package Dependencies with Pipenv

To uninstall all the dependencies in a Pipenv project: 

  1. Open a command or terminal window
  2. cd into the project directory
  3. pipenv uninstall --all

How to Uninstall a Package Installed With Setuptools

Any packages that have been configured and installed with setuptools used the following command: 

python setup.py install 

Unfortunately, there is no python setup.py uninstall command. To uninstall a package installed with setup.py, use the pip command:

pip uninstall 

Be aware that there are a few exceptions that cannot be uninstalled with pip, including:

  • Distutils packages, which do not provide metadata indicating which files were installed.
  • Script wrappers installed by the setup.py develop command.

Next Steps

Resolving packages when installing or uninstalling an environment can be an extremely slow [or even manual] process. You can speed things up considerably using the ActiveState Platform, which automatically resolves dependencies for you–fast! Get started free on the ActiveState Platform.

Or just install Python 3.9 and use the included command line interface, the State Tool, to “state install” the packages you need:

>state install numpy

╔════════════════════╗
║ Installing Package ║
╚════════════════════╝

Updating Runtime

────────────────

Changes to your runtime may require some dependencies to be rebuilt.

numpy includes 2 dependencies, for a combined total of 8 new dependencies. 

Building                                    8/8

Installing                                  8/8

Package added: numpy

How do I uninstall Python from source?

It's possible that your python installation created a setup.py file, in which case you can do a: setup.py uninstall Here are a few links that may be useful: serverfault.com/questions/50323/….
Install checkinstall..
Use checkinstall to make a deb of your Python installation..
Use dpkg -r to remove the deb..

How do I completely uninstall a Python package?

How to Uninstall Packages in a Python Virtual Environment.
Open a command or terminal window [depending on the operating system].
cd into the project directory..
pip uninstall .

How do I uninstall Python imports?

Uninstalling/removing Python packages using Pip.
Open a terminal window..
To uninstall, or remove, a package use the command '$PIP uninstall '. This example will remove the flask package. ... .
The command will ask for confirmation after listing the files to be removed..

Can I uninstall old Python versions?

Assuming you have an older version X.Y installed, scroll through the list of programs, and for each Python X.Y package that has been installed, select it in the list and click Remove. Note that most packages will be listed as Python X.Y package_name-package_version, such as Python 2.5 numpy-1.0.

Chủ Đề