How do I update a Python package?

后端 未结 12 2189
半阙折子戏
半阙折子戏 2020-11-29 15:47

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.

相关标签:
12条回答
  • 2020-11-29 15:52
    • Method 1: Upgrade manually one by one

    pip install package_name -U
    
    • Method 2: Upgrade all at once (high chance rollback if some package fail to upgrade

    pip install $(pip list --outdated --format=columns |tail -n +3|cut -d" " -f1) --upgrade
    
    • Method 3: Upgrade one by one using loop

    for i in  $(pip list --outdated --format=columns |tail -n +3|cut -d" " -f1); do pip install $i --upgrade; done
    
    0 讨论(0)
  • 2020-11-29 15:54

    The best way I've found is to run this command from terminal

    sudo pip install [package_name] --upgrade
    

    sudo will ask to enter your root password to confirm the action.


    Note: Some users may have pip3 installed instead. In that case, use

    sudo pip3 install [package_name] --upgrade
    
    0 讨论(0)
  • 2020-11-29 16:00

    To automatically upgrade all the outdated packages (that were installed using pip), just run the script bellow,

    pip install $(pip list --outdated | awk '{ print $1 }') --upgrade
    

    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,

    #!/bin/bash
    sudo pip install $(pip list --outdated | awk '{ print $1 }') --upgrade
    

    Then use the following lines of script to prepare it:

    sudo chmod +x pip-upgrade
    sudo cp pip-upgrade /usr/bin/
    

    Then, just hit pip-upgrade and voila!

    0 讨论(0)
  • 2020-11-29 16:00

    Use pipupgrade!

    $ pip install pipupgrade
    $ pipupgrade --latest --interactive
    

    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.

    0 讨论(0)
  • 2020-11-29 16:02
    pip install -U $(pip list --outdated | awk 'NR>2 {print $1}')
    
    0 讨论(0)
  • 2020-11-29 16:02

    In Juptyer notebook, a very simple way is

    !pip install <package_name> --upgrade
    

    So, you just need to replace with the actual package name.

    0 讨论(0)
提交回复
热议问题