How to delete pip package

How to delete pip package

How to Uninstall a Package in Python using PIP

In this short tutorial, you’ll see how to uninstall a package in Python using PIP.

If you’re using Windows, you’ll be able to uninstall a Python package by opening the Windows Command Prompt, and then typing this command:

Note : the above method would only work if you already added Python to Windows path. Don’t worry if you don’t know what it means, as you’ll see the full steps to uninstall a package in Python from scratch.

Steps to Uninstall a Package in Python using PIP

(1) First, type Command Prompt in the Windows Search Box

(2) Next, open the Command Prompt, and you’ll see the following screen with your user name (to avoid any permission issues, you may consider to run the Command Prompt as an administrator ):

(3) In the Command Prompt, type “cd\” as this command will ensure that your starting point has only the drive name:

(4) Press Enter. Now you’ll see the drive name C:\>

(5) Locate your Python Scripts path. The Scripts folder can be found within the Python application folder, where you originally installed Python.

Here is an example of a Python Scripts path:

C:\Users\Ron\AppData\Local\Programs\Python\Python39\Scripts

(6) In the Command Prompt, type cd followed by your Python Scripts path:

(7) Press Enter, and you’ll see the following:

(8) Finally, to uninstall a package in Python, use this command, while specifying the package name that you’d like to uninstall:

(9) To proceed with the removal of the package, type “y” and then press Enter:

Your Python package will now be removed from Python.

What if you changed your mind, and decided to install that package again?

If that’s the case, you may use the PIP install method to add the package into Python.

Pip Uninstall | Uninstall a pip package

We will show you how to uninstall a pip package that you installed with pip install. pip is a package management tool that can be used to install and manage software packages written in Python, which can be found in the Python Package Index (PyPI). pip is a recursive acronym that can stand for either “Pip Installs Packages” or “Pip Installs Python”. Alternatively, pip stands for “preferred installer program”. Let’s see how you can use pip to remove packages.

How to delete pip package. Смотреть фото How to delete pip package. Смотреть картинку How to delete pip package. Картинка про How to delete pip package. Фото How to delete pip packageIf you followed one of our previous tutorials about how to install and use pip on Ubuntu 16.04 or how to install and use pip on CentOS 7 and you installed some Python packages that you don’t want to use anymore, you can easily uninstall them using pip.

Table of Contents

1. Pip List Installed

First of all, connect to your Linux server via SSH. Then list the currently installed packages using the following command:

How to delete pip package. Смотреть фото How to delete pip package. Смотреть картинку How to delete pip package. Картинка про How to delete pip package. Фото How to delete pip packageThe command above will provide you with an output similar to the one below:

2. Pip Uninstall

Once you run the command, pip will ask you to confirm the action. Answer with y to confirm and the package will be uninstalled from the system.

How to delete pip package. Смотреть фото How to delete pip package. Смотреть картинку How to delete pip package. Картинка про How to delete pip package. Фото How to delete pip package3. Pip Uninstall All

The easiest way to remove all packages installed by pip is by executing the following command:

4. Create a Bash Alias

We suggest you create a bash alias with his command:

Then all you have to do is just run

5. Alternative Solution for pipenv

If you are using pipenv you can just run:

For more information on how to use the pip uninstall, you can refer to the pip documentation for pip uninstall and more usage examples.

How to delete pip package. Смотреть фото How to delete pip package. Смотреть картинку How to delete pip package. Картинка про How to delete pip package. Фото How to delete pip package

Of course, you don’t have to use pip uninstall to remove installed packages, if you use one of our Managed Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to uninstall with pip. They are available 24×7 and will take care of your request immediately.

How To Uninstall A Package with Pip?

Python Pip command provides search, install, update, uninstall packages. We can use pip command to uninstall packages easily even there are some alternatives like easy_install.

List Already Installed Python Packages with Pip

Before uninstalling or removing Python packages with pip we will list already installed Python packages. We will use list command for pip like below.

How to delete pip package. Смотреть фото How to delete pip package. Смотреть картинку How to delete pip package. Картинка про How to delete pip package. Фото How to delete pip packageList Already Installed Python Packages with Pip

We can see that the following information is provided by listing installed packages.

List/Display Python Packages Information, Version

We can also show a given package complete information with the show command which can be useful before uninstalling it. In this example, we will show information about the Python package named Django.

How to delete pip package. Смотреть фото How to delete pip package. Смотреть картинку How to delete pip package. Картинка про How to delete pip package. Фото How to delete pip packageList/Display Python Packages Information, Version

Uninstall/Remove Python Package with Pip, Pip2, Pip3

How to delete pip package. Смотреть фото How to delete pip package. Смотреть картинку How to delete pip package. Картинка про How to delete pip package. Фото How to delete pip packageUninstall/Remove Python Package with Pip

We can see that the directories and files removed are listed and a confirmation is shown where we will input y in order to accept the removal. After the remove/uninstall completed we will be shown Successfully uninstalled Django-2.2.5

If we want to remove packages related to the Python2 we can use the same command for the pip2 command like below.

If we want to remove packages related to the Python3 we can use the same command for the pip3 command like below.

Uninstall/Remove Python Package with Requirements with Pip

AND we will remove this requirements.txt file content like below.

Uninstall/Remove Python Package Without Asking Confirmation with Pip

Uninstall/Remove Python Package For Specific User with Pip

Uninstall/Remove Python Package with easy_install

Pip Install: Install and Remove Python Packages

Pip install is the command you use to install Python packages with the Pip package manager. If you’re wondering what Pip stands for, the name Pip is a recursive acronym for ‘Pip Installs Packages.’ There are two ways to install Python packages with pip:

But before we start, let’s make sure pip itself is installed!

Table of contents

Python: Install Pip

First things first: we need to install pip itself. The good news is that Pip is probably already present on your system. Most Python installers also install Pip. Python’s pip is already installed if you are using Python 2 >=2.7.9 or Python 3 >=3.4 downloaded from python.org. If you are working in a virtual environment, pip also gets installed for you.

So before you try to install Pip, make sure it’s not already present on your system. Open a terminal (Linux/MacOS) or a Windows shell, and type in the following command:

If the pip command gives an error, try pip3 instead. Python 2 and 3 can be installed next to each other on some systems. On those systems, pip is often installed under the name pip3 :

If that didn’t work either, you can try the pip module that is built into most modern Python installations:

If that failed too, you need to install it yourself, so let’s take a look at how you can manually install it. You should do this only as a last resort, and I strongly suggest you first check if your Python installation went well first.

Install Pip on Windows and Mac

On Windows and Mac, you can download a Python script to install pip, called get-pip.py. Download the file and run it with Python from a command prompt or terminal window:

Make sure you are in the directory where the script was downloaded.

Install Pip on Linux (Ubuntu, Debian, Redhat)

You can install pip with the apt package manager on Debian, Ubuntu, Linux Mint, and other Debian derivatives. It’s the most recommended method and ensures your system will stay in a consistent state.

If your system uses the yum package manager, you can try the following:

Pip is part of EPEL (Extra Packages for Enterprise Linux), so you might need to enable that first.

If these methods fail, you can also download a Python script that will install pip for you, with the following commands:

Pip Install Python packages

I can’t stress this enough: preferably, you install packages inside a virtual environment. And the good news: pip is present inside your virtual environment by default. Because everything in our venv is installed locally, you don’t need to become a superuser with sudo or su and you don’t risk package version conflicts.

Having said that, you can also install packages outside of a Python venv. This is only recommended for the more generic packages that you might need in a lot of scripts, or if the package functions as a more generic tool. Some example libraries that would fit this description would be Numpy and Pandas, a REPL alternative like ipython, or complete environments like Jupyter Notebook.

Install locally (no root or super user)

Luckily, these days the Python installation on most OSes configures your system in such a way that you don’t have to become an administrator (or root on a Unix system) to install packages outside of a venv.

However, you won’t always have the super-user rights to install packages system-wide, e.g. when working on a shared or locked down system at work or school.

In fact, installing packages in the local install directory is often the default these days when running outside of a virtual environment. So Let’s try to upgrade our account-wide pip installation first. Make sure you are not currently in a virtual environment and enter:

These commands asked pip to install pip in your user account, and update it if it’s already installed. On my system, this gives me the message that the requirement is already satisfied, meaning that pip is already up-to-date.

Now, as an exercise, you could try to install ipython. It’s a great alternative to the standard Python REPL.

Install Python packages in a venv

You just installed a package inside of your virtual environment, and as such it will only be accessible when you activate this venv.

Install Python packages system-wide

Let me first repeat that I don’t recommend this. If you jumped in here without reading the rest of the topic, please read the section above about installing packages in your user account or in a virtual environment first.

On Linux, you can install a package system-wide by doing so as the root user. I strongly suggest you don’t, but here’s how to do it by using sudo :

Pip install requirements.txt file

In a virtual environment, installing specific versions of packages is a good habit. It ensures that you reap the full benefits of using virtual environments in the first place. After all, we do this to make sure our software always works as intended by pinning down specific dependency versions.

A requirements.txt file contains a simple list of dependencies, one per line. In its most simple form, it could look like this:

But what we really want is to pin the versions. That’s not hard either:

What version range to pick

How do you know what range to use? It’s a topic that most tutorials and courses seem to avoid. Unfortunately, there are no hard rules to this. You will have to read the release notes and such from the package(s) in question.

For example, let’s assume you are using two packages, A and B. Perhaps you know that a certain feature became available in package A, version 3.1.0, so you require at least that version. But from the news, you learned that the author is planning a major overhaul of package A’s API in version 4.0.0. In addition, package B is a bit stale and poorly maintained. It’s been stuck at version 0.6.2 for ages and requires package A version 3.1.6 or lower (while A is currently at 3.5.0). You could define the following constraints to ensure everything works together nicely:

You see, it requires some juggling sometimes to define version constraints properly. That’s why many developers use an alternative to Pip, like Poetry or Pipenv. These tools offer advanced dependency management and will resolve all the dependencies automatically, if possible. We take a close look at the package managers further on in this course. Right now, we’re making sure you understand the basics. This way, the package managers will seem less magical, and you’ll better understand what they do for you. This is not the fun stuff when it comes to

Pip freeze

Creating your requirements file using pip’s freeze option can make your life a little easier. First, write your software and install all the requirements you need as you go. Once you’re done and everything seems to work fine, use the following command:

Pip created a requirements.txt file with all the currently installed dependencies, including version numbers. Neat! You may choose to relax the versions a little, e.g. to allow for minor updates (bug fixes, security fixes) to a package. But remember that it’s a risk too: there’s always a chance of ending up with a project that doesn’t work as intended because one of the requirements changed the behavior of its API or something.

Pip Install from a requirements.txt file

Finally, to install all the dependencies listed in this file, use:

It’s an instruction that you’ll often see when reading the installation instructions for Python projects, and now you know exactly what it does and how it works!

The default PyPI repository is located at https://pypi.org/simple. You can use an alternative repository as well, though. For example, if your company only allows a subset of approved packages from an internal mirror. Or perhaps your company has a private mirror with their own package. This repository can be located on an HTTP(s) URL or on a file system location.

To specify a custom repository, use the -i or —index-url option, like so:

The URL must point to a repository compliant with PEP 503 (the simple repository API) or a local directory laid out in the same format.

Pip has the option to do an editable install, meaning you can install a package from a local source. But instead of copying the package files to some location on your system, pip creates symlinks to the codebase you’re installing it from. This way, you can work on the project and make changes and be able to directly test those changes without constantly reinstalling new versions of the package.

There are a number of reasons why you might need this option:

Typically, you will be working on a project using a version control system like git. While inside the root of the repository, you would install the project with:

If you’re not in the project root, you can simply supply the path to the package source code instead of using the dot.

Pip uninstall

To uninstall a package with pip, we can use the ‘uninstall’ subcommand, e.g. to uninstall simplejson :

In line with the pip install command using a requirements file, you can also use such a file to uninstall packages:

More pip commands

We can also use pip to get more info about a package or the currently installed packages. Pip also offers a search function. Let’s explore these additional commands.

Pip list: listing installed packages

To list all the currently installed packages using pip, use the following command:

It will show both package names and versions. When you run the command inside a virtual environment, only the packages of the venv are shown. All account-wide or system-wide packages will be listed if you run it outside of a venv.

Pip show: get package details

Now that you know which packages are installed, you may need to inspect one in more detail. For this, we have the ‘show’ sub-command:

It’s a quick way to look up what a package is and does, and who authored it.

Pip search: find packages

We used to be able to find all packages matching a certain string using pip. Although convenient, this introduced a big load on the servers over at PyPI. Unfortunately, they’ve decided to disable the feature. Luckily, we still have search engines like DuckDuckGo, Google, and Bing to find stuff!

The Python Package Index

We haven’t talked extensively about the Python Package index yet, located at pypi.org. The site offers us a few things:

To be honest, the Python package index is lacking somewhat and I don’t think many people use the site itself.

PyPI search function

An example of how to site’s functionality doesn’t offer much value is the search function. If you know exactly what you are looking for, it’s fine. E.g. let’s try a search for the immensely popular requests package. It will show up first and we can click through to the information page here where we can see things like:

All this info is provided by the package authors, so keep that in mind.

Now suppose we can’t remember the name requests and we search for the word HTTP instead:

How to delete pip package. Смотреть фото How to delete pip package. Смотреть картинку How to delete pip package. Картинка про How to delete pip package. Фото How to delete pip packageA search on PyPI.org

You can try and see for yourself if you want: the requests package is nowhere to be found. So if you need to discover a library to do a specific thing, like doing HTTP requests, I strongly suggest you use Google instead.

A simple Google search will yield that Python has a built-in HTTP library, which might be good enough. However, the first results page also has several mentions of requests, giving us a strong indicator that this package is used by many as well.

PyPI Categories

If you decide to browse the categories instead, you’ll also find that they aren’t very helpful. Luckily, the Python community is strong and many sites (like Python Land!) fill in the gaps and offer good advice on which packages to use.

So in short: the PyPI site won’t be very useful for discovery, but it will be more than adequate in giving you package information and links to documentation and source repositories and such.

Keep learning

Related posts you might like

About Erik van Baaren

Erik is the owner of Python Land and the author of many of the articles and tutorials on this website. He’s been working as a professional software developer for 25 years, and he holds a Master of Science degree in computer science. His favorite language of choice: Python! Writing good articles takes time and effort. Did you like this tutorial? You can buy him a coffee to show your appreciation.

How to Uninstall Python Packages

How to delete pip package. Смотреть фото How to delete pip package. Смотреть картинку How to delete pip package. Картинка про How to delete pip package. Фото How to delete pip package

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).

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:

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:

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

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:

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.

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:

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:

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:

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *