We’ve had a run of Python packages recently and you can tell that I’m a fan because today we will discuss how to update Python packages that were installed via PIP. This should be a pretty easy article to follow along with.
Before diving into the world of installing Python packages from a centralized repository (via PIP), you should probably be familiar with the entire process. So, read these two articles before proceeding:
And then follow up with this article:
It’s important to upgrade the packages you’ve installed with PIP. All software requires updates. Bugs are fixed with newer software but, more importantly, security issues are addressed with updates. This doesn’t just apply to Python. It applies to your whole computer. Software gets updated and you need to apply those updates.
So, today we’re going to do some maintenance and we’re going to update Python packages. Rather than waste time with a long intro, let’s get started!
Update Python Packages:
Just so you know, Python packages are installed in the terminal. So, it stands to reason that updates are also done in the terminal. To follow along in this article, you will need an open terminal. So, if you want to update Python packages you should start by opening a terminal. You can usually just
With your terminal open, let’s first ensure PIP is installed with this command:
1 | pip --version |
Next, make sure PIP is updated to the newest version:
1 | pip install --upgrade pip |
With PIP upgraded to the most current version, you can check to see which Python packages you have previously installed. That’s done like this:
1 | pip list |
Now, you can see which packages can be updated to newer packages:
1 | pip list --outdated |
That will give you an output similar to this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | $ pip list --outdated Package Version Latest Type ------------------ ---------------- ----------- ----- argcomplete 1.10.3 3.3.0 wheel async-timeout 4.0.1 4.0.3 wheel bcrypt 3.2.0 4.1.2 wheel beautifulsoup4 4.8.2 4.12.3 wheel blinker 1.4 1.7.0 wheel Brotli 1.0.9 1.1.0 wheel build 1.0.3 1.2.1 wheel certifi 2020.6.20 2024.2.2 wheel chardet 3.0.4 5.2.0 wheel click 8.0.3 8.1.7 wheel colorama 0.4.4 0.4.6 wheel |
Now, you can update the packages, like so:
1 | pip install -U <package_name> |
You can also do multiple packages at the same time:
1 | pip install -U <package_name> <package_name> |
By doing this, you can update your Python packages, at least those installed via PIP. That is indeed pretty easy.
However, I have a command that I certainly didn’t come up with. This is a command I found in my notes and I do not see a reference URL – or I’d cite the source. Doing some searching, I saw that this command is referenced at multiple sites. So, finding the source is problematic for me.
If you want to upgrade all the Python packages at once, try this command:
1 | pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U |
I tested this and it appears to work well enough. PIP does love to throw errors in the terminal but generally works okay. That command should update all the packages you’ve installed with PIP – including any Python dependencies that were installed at the same time.
See? It’s pretty easy to update Python packages…
Closure:
Well, now you know how to update Python packages. I figured that this was an important article to write. If you’re going to use PIP to install Python packages, you might as well know how to keep yourself secure and how to keep yourself updated. That seemed reasonable.
However, my Python skills aren’t that great. I can do a Hello World program and that’s about it. I haven’t even done that in a while. So, don’t go asking me detailed Python questions! I probably won’t have an answer. My use is pretty limited to things I can trivially install with PIP.
Also, you may not want to ask me questions. While I’ll be polite, my time is constrained these days. I’m just as likely to refer you to a forum or two. You can ask questions. If they’re good, I’ll maybe answer them in an article. I’m just pointing out that you shouldn’t expect too much from me.
“If you don’t expect too much from me, you might not be let down.”
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.