- How to update/upgrade a package using pip?
- 6 Answers 6
- How do I update a Python package?
- 12 Answers 12
- Use pipupgrade!
- How do I update pip itself from inside my virtual environment?
- 17 Answers 17
- How To Update/Upgrade A Python Package with Pip?
- List Installed Python Packages
- Check If A Python Package Is Installed
- List Outdated Python Packages
- Upgrade/Update Python Package To The Latest Version
- Upgrade/Update Python Package To The Specific Version
- Downgrade Python Package To The Specific Version
- Как обновить pip через командную строку
How to update/upgrade a package using pip?
What is the way to update a package using pip? those do not work:
I know this is a simple question but it is needed as it is not so easy to find (pip documentation doesn’t pop up and other questions from stack overflow are relevant but are not exactly about that)
6 Answers 6
Using sudo will ask to enter your root password to confirm the action, but although common, is considered unsafe.
If you do not have a root password (if you are not the admin) you should probably work with virtualenv.
You can also use the user flag to install it on this user only.
For a non-specific package and a more general solution you can check out pip-review, a tool that checks what packages could/should be updated.
tl;dr script to update all installed packages
If you only want to upgrade one package, refer to @borgr’s answer. I often find it necessary, or at least pleasing, to upgrade all my packages at once. Currently, pip doesn’t natively support that action, but with sh scripting it is simple enough. You use pip list , awk (or cut and tail ), and command substitution. My normal one-liner is:
This will ask for the root password. If you do not have access to that, the —user option of pip or virtualenv may be something to look into.
use this code in teminal :
for example i want update pip pakage :
Save as xx.py
Then run Python3 xx.py
Environment: python3.5+ pip10.0+
To upgrade pip for Python3.4+, you must use pip3 as follows:
This will upgrade pip located at: /usr/local/lib/python3.X/dist-packages
Otherwise, to upgrade pip for Python2.7, you would use pip as follows:
This will upgrade pip located at: /usr/local/lib/python2.7/dist-packages
How do I update a Python package?
I’m running Ubuntu 9:10 and a package called M2Crypto is installed (version is 0.19.1). I need to download, build and install the latest version of the M2Crypto package (0.20.2).
The 0.19.1 package has files in a number of locations including (/usr/share/pyshared and /usr/lib/pymodules.python2.6).
How can I completely uninstall version 0.19.1 from my system before installing 0.20.2?
12 Answers 12
You might want to look into a Python package manager like pip. If you don’t want to use a Python package manager, you should be able to download M2Crypto and build/compile/install over the old installation.
The best way I’ve found is to run this command from terminal
sudo will ask to enter your root password to confirm the action.
Note: Some users may have pip3 installed instead. In that case, use
To automatically upgrade all the outdated packages (that were installed using pip), just run the script bellow,
Here, pip list —outdated will list all the out dated packages and then we pipe it to awk, so it will print only the names. Then, the $(. ) will make it a variable and then, everything is done auto matically. Make sure you have the permissions. (Just put sudo before pip if you’re confused) I would write a script named, pip-upgrade The code is bellow,
Then use the following lines of script to prepare it:
Then, just hit pip-upgrade and voila!
- Via windows command prompt, run: pip list —outdated You will get the list of outdated packages.
- Run: pip install [package] —upgrade It will upgrade the [package] and uninstall the previous version.
Again, this will uninstall the previous version of pip and will install the latest version of pip.
- Method 1: Upgrade manually one by one
- Method 2: Upgrade all at once (high chance rollback if some package fail to upgrade
- Method 3: Upgrade one by one using loop
I think the best one-liner is:
Use pipupgrade!
pipupgrade helps you upgrade your system, local or packages from a requirements.txt file! It also selectively upgrades packages that don’t break change. Compatible with Python2.7+, Python3.4+ and pip9+, pip10+, pip18+.
NOTE: I’m the author of the tool.
Open Command prompt or terminal and use below syntax
How was the package originally installed? If it was via apt, you could just be able to do apt-get remove python-m2crypto
If you installed it via easy_install, I’m pretty sure the only way is to just trash the files under lib, shared, etc..
My recommendation in the future? Use something like pip to install your packages. Furthermore, you could look up into something called virtualenv so your packages are stored on a per-environment basis, rather than solely on root.
With pip, it’s pretty easy:
But you can also install from git, svn, etc repos with the right address. This is all explained in the pip documentation
How do I update pip itself from inside my virtual environment?
I’m able to update pip-managed packages, but how do I update pip itself? According to pip —version , I currently have pip 1.1 installed in my virtualenv and I want to update to the latest version.
What’s the command for that? Do I need to use distribute or is there a native pip or virtualenv command? I’ve already tried pip update and pip update pip with no success.
17 Answers 17
pip is just a PyPI package like any other; you could use it to upgrade itself the same way you would upgrade any package:
On windows there seem to be a problem with binaries that try to replace themselves, this method works around that limitation.
In my case my pip version was broken so the update by itself would not work.
I tried all of these solutions mentioned above under Debian Jessie. They don’t work, because it just takes the latest version compile by the debian package manager which is 1.5.6 which equates to version 6.0.x. Some packages that use pip as prerequisites will not work as a results, such as spaCy (which needs the option —no-cache-dir to function correctly).
So the actual best way to solve these problems is to run get-pip.py downloaded using wget, from the website or using curl as follows:
This will install the current version which at the time of writing this solution is 9.0.1 which is way beyond what Debian provides.
Upgrading pip using ‘pip install —upgrade pip‘ does not always work because of the dreaded cert issue: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version
I like to use the one line command for virtual envs:
Or if you want to install it box wide you will need
you can give curl a -s flag if you want to silence the output when running in an automation script.
In case you are using venv any update to pip install will result in upgrading the system pip instead of the venv pip. You need to upgrade the pip bootstrapping packages as well.
In my case this worked from the terminal command line in Debian Stable
To get this to work for me I had to drill down in the Python directory using the Python command prompt (on WIN10 from VS CODE). In my case it was in my «AppData\Local\Programs\Python\python35-32» directory. From there now I ran the command.
This worked and I’m good to go.
Open Command Prompt with Administrator Permissions, and repeat the command:
pip version 10 has an issue. It will manifest as the error:
The solution is to be in the venv you want to upgrade and then run:
rather than just
I was in a similar situation and wanted to update urllib3 package. What worked for me was:
I had installed Python in C:\Python\Python36 so I went to the Windows command prompt and typed «cd C:\Python\Python36 to get to the right directory. Then entered the «python -m install —upgrade pip» all good!
On my lap-top with Windows 7 the right way to install latest version of pip is:
Single Line Python Program
The best way I have found is to write a single line program that downloads and runs the official get-pip script. See below for the code.
The official docs recommend using curl to download the get-pip script, but since I work on windows and don’t have curl installed I prefer using python itself to download and run the script.
Here is the single line program that can be run via the command line using Python 3:
This line gets the official «get-pip.py» script as per the installation notes and executes the script with the «exec» command.
For Python2 you would replace «urllib.request» with «urllib2»:
Precautions
It’s worth noting that running any python script blindly is inherently dangerous. For this reason, the official instructions recommend downloading the script and inspecting it before running.
That said, many people don’t actually inspect the code and just run it. This one-line program makes that easier.
How To Update/Upgrade A Python Package with Pip?
Pip is a popular command used to manage Python packages. Pip command is also used for updating/upgrading already installed Python packages.
List Installed Python Packages
Before updating or upgrading an installed Python package we will list already installed packages. We will use the list command which will display the complete name and the version of the installed packages.
Check If A Python Package Is Installed
In the previous example, we have just listed all installed packages and versions. We can also check if a specific python package is already installed. We will also use grep command by providing the name of the package we want to check.
List Outdated Python Packages
Pip command also provides —outdated options with the list command which will list outdated and already installed python packages.
Upgrade/Update Python Package To The Latest Version
We will use the install command with the —upgrade option and also provide the package name. In this example, we will update/upgrade the package named Django to the latest version. We will also provide the —user option. Alternatively to the —upgrade we can use -U which is the short form.
From the screenshot, we see that first the Django version 2.0 is found. Django version 2.0 is uninstalled and then Django version 2.2.5 is installed which will complete the upgrade/update of the Django.
Upgrade/Update Python Package To The Specific Version
In the previous example, we have updated the Django python package to the latest version. We can also update/upgrade a python package into a specific version which is not the latest. In this example, we will upgrade/update a specific version which is not the latest with the equal signs. We will not use the —upgrade option but specify the upgraded version.
We can see that the currently installed version is Django 2.0 but we will upgrade it into version 2.2 .
Downgrade Python Package To The Specific Version
We can also downgrade the installed package into a specific version. We will specify the Python package name with the version we want to downgrade by using equation signs like below. In this example, we will downgrade the Django package to version 2.0.
Как обновить pip через командную строку
Когда мы узнаём, что необходимо обновить pip (менеджер пакетов в Python)? Как правило, во время загрузки каких-либо модулей.
После инсталляции PyQt5 появилось сообщение о необходимости обновления версии pip 20.1.1 до версии 20.2.2. Обратите внимание, что указана и команда при помощи который можно сделать обновление
Итак, наша задача обновить версию pip на компьютере, работающем под управлением Windows. Первоначально запускаем cmd.exe — интерпретатор командной строки. После запуска, вводим команду обновления pip для Питона python — m pip install — upgrade pip и жмём Enter.
Обновление pip прошло успешно
Если при обновлении pip возникает ошибка, попробуйте сначала перейти в каталог с файлом python.exe. Для этого нужно знать местонахождение этого файла. В нашем случае абсолютный путь к каталогу с файлом c:\Users\Admin\AppData\Local\Programs\Python\Python38-32
Шаг 1. Переходим в корневой каталог системного диска при помощи команды cd\
При помощи команды cd\ мы перешли в корень диска «С»
Шаг 2. Теперь перейдём в каталог, в котором находится Питон. Снова будем использовать команду cd с указанием абсолютного пути:
Теперь мы находимся в папке с файлом python.exe. Python38-32 означает, что это версия Python 3.8 32-х разрядная
Шаг 3. Запускаем уже известную нам команду обновления pip python — m pip install — upgrade pip
Поскольку мы ранее уже обновили pip, появилось сообщение «Requirements already up-to date», которое означает, что уже установлена актуальная версия pip
Если на вашем компьютере установлено несколько версий Python, то для каждой нужно отдельно обновлять pip, указывая абсолютный путь. В качестве примера мы обновим pip для 64-битной версии Python 3.7 также установленном на нашем ПК.
Обновление pip для Python 3.7 прошло успешно