Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update/upgrade a package using pip?

Tags:

python

pip

What is the way to update a package using pip? those do not work:

pip update pip upgrade 

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)

like image 614
borgr Avatar asked Nov 02 '17 09:11

borgr


People also ask

Can I use pip to upgrade Python?

pip is designed to upgrade python packages and not to upgrade python itself. pip shouldn't try to upgrade python when you ask it to do so. Don't type pip install python but use an installer instead.

What is Python pip install -- upgrade pip?

Python pip comes pre-installed on 3.4 or older versions of Python. To check whether pip is installed or not type the below command in the terminal. This command will tell the version of the pip if pip is already installed in the system.

Does pip install the latest version of package?

By default, pip installs the latest version, but here you pin it to a specific one.


2 Answers

The way is

pip install <package_name> --upgrade 

or in short

pip install <package_name> -U 

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.

pip install <package_name> --upgrade --user 
like image 52
borgr Avatar answered Oct 21 '22 23:10

borgr


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.

To install:

$ pip install pip-review 

Then run:

$ pip-review --interactive requests==0.14.0 is available (you have 0.13.2) Upgrade now? [Y]es, [N]o, [A]ll, [Q]uit y 
like image 29
as - if Avatar answered Oct 22 '22 01:10

as - if