Python pip remove packages

How to Uninstall Python Packages

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 .

Читайте также:  Javascript date parsing from string

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

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:

    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:

    Output should be similar to:

    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:

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

    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 To Uninstall Python Packages

    Uninstalling Python packages and their dependencies can be done using the pip package manager. The pip package manager is a built-in tool for Python that can be used to install, upgrade, and uninstall packages.

    Following is a step-by-step explanation of how to uninstall a package in Python using pip:

    1. Open a terminal/command prompt
    2. Check if pip is installed
    3. List installed packages
    4. Uninstall the package
    5. Verify that the package is uninstalled

    Open a terminal/command prompt

    Open a terminal/command prompt on your system.

    Check if pip is installed

    Check if pip is installed on your system by running the following command:

    If pip is installed, you will see its version number in the output. If not, you will see an error message.

    List installed packages

    List all the packages that are currently installed on your system using the following command:

    Above command command will display a list of all the packages installed on your system along with their version numbers.

    Uninstall the package

    To uninstall a package, use the following command:

    Replace package_name with the name of the package you want to uninstall.

    If the package has any dependencies that are no longer required, pip will also prompt you to uninstall them. You can choose whether or not to uninstall them by typing y or n.

    Verify that the package is uninstalled

    After the package is uninstalled, verify that it is no longer installed on your system by running the pip list command again.

    If the package is no longer listed, then it has been successfully uninstalled.

    Now you have successfully uninstalled a package in Python using pip.

    Uninstalling python packages and dependencies

    Uninstalling Python packages and dependencies

    If the package has dependencies that are no longer required, pip will prompt you to uninstall them as well. You can choose to uninstall the dependencies by typing y or to keep them by typing n.

    Verify the package is uninstalled

    To verify that the package has been successfully uninstalled, run the pip list command again:

    If the package is no longer listed, then it has been successfully uninstalled.

    Uninstall dependencies

    If you have uninstalled a package and want to remove its dependencies, you can use the pip autoremove command:

    Above command will remove any packages that are no longer needed by your system.

    It’s important to note that, be careful when using the pip autoremove command as it may remove packages that are still being used by other packages. It’s always a good idea to verify which packages will be removed before running this command.

    Now you have successfully uninstalled a Python package and its dependencies using pip.

    Uninstall packages in a Python virtual environment

    Uninstalling packages in a Python virtual environment is similar to uninstalling packages in a standard Python environment. However, it is important to activate the virtual environment before running the uninstallation command.

    Following are the steps to uninstall packages in a Python virtual environment:

    Activate the virtual environment

    Navigate to the directory where the virtual environment is installed and activate it. The activation command depends on the operating system and the shell you are using.

    On Windows using Command Prompt, you can activate the virtual environment by running the following command:

    On macOS or Linux using bash shell, you can activate the virtual environment by running the following command:

    Uninstall the package

    Once the virtual environment is activated, you can use the pip uninstall command to uninstall the package. Replace package_name with the name of the package you want to uninstall:

    Verify the package is uninstalled

    To verify that the package has been successfully uninstalled, run the following command:

    Above command will display a list of all installed packages in the virtual environment. If the package you just uninstalled is not listed, then it has been successfully uninstalled.

    Deactivate the virtual environment

    After you have uninstalled the package, you can deactivate the virtual environment by running the following command:

    Above command will return your command prompt to the standard shell environment.

    Now you have successfully uninstalled a package in a Python virtual environment.

    Uninstall Python Package Dependencies With Pipenv

    Pipenv is a tool for managing Python environments and packages. It provides a way to install packages in a virtual environment, along with their dependencies. To uninstall a package and its dependencies using Pipenv, follow these steps:

    Activate the Pipenv environment

    Open your command line interface and navigate to the directory where your Pipenv environment is located. Activate the environment by running the following command:

    Above command will activate the virtual environment and set the environment variables needed to use Pipenv.

    Uninstall the package and its dependencies

    To uninstall a package and its dependencies, use the following command:

    Replace package_name with the name of the package you want to uninstall.

    For example, if you want to uninstall the numpy package and its dependencies, you can type:

    Above command will remove the numpy package and its dependencies from your virtual environment.

    Verify the package and its dependencies are uninstalled

    To verify that the package and its dependencies have been successfully uninstalled, use the pipenv graph command to list all the packages installed in the virtual environment:

    Above command will display a list of all the packages installed in the virtual environment, along with their dependencies. If the package and its dependencies are no longer listed, then they have been successfully uninstalled.

    Deactivate the Pipenv environment

    After you have uninstalled the package and its dependencies, you can deactivate the virtual environment by running the following command:

    Above command will return your command prompt to the standard shell environment.

    Now you have successfully uninstalled a package and its dependencies using Pipenv.

    Uninstall A python Package Installed With Setuptools

    Uninstalling a Python package installed with Setuptools is similar to uninstalling a package installed with pip.

    1. Python Datatype conversion
    2. Python Mathematical Function
    3. Basic String Operations in Python
    4. Python Substring examples
    5. How to check if Python string contains another string
    6. Check if multiple strings exist in another string : Python
    7. Memory Management in Python
    8. Python Identity Operators
    9. What is a None value in Python?
    10. How to Install a Package in Python using PIP
    11. How to update/upgrade a package using pip?
    12. How to call a system command from Python
    13. How to use f-string in Python
    14. Python Decorators (With Simple Examples)
    15. Python Timestamp Examples

    Источник

Оцените статью