How to Update a Python Package

How do I update a Python package?

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.

How to update/upgrade a package using pip?

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

How to upgrade all Python packages with pip

There isn't a built-in flag yet, but you can use:

pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U

For older versions of pip:

pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U


  • The grep is to skip editable ("-e") package definitions, as suggested by @jawache. (Yes, you could replace grep+cut with sed or awk or perl or...).

  • The -n1 flag for xargs prevents stopping everything if updating one package fails (thanks @andsens).


Note: there are infinite potential variations for this. I'm trying to keep this answer short and simple, but please do suggest variations in the comments!

How to update the packages in ipython like jupyter & spyder

You just forgot put the ! before pip install --upgrade pip.

Do this: !pip install --upgrade pip

See this for more information, if you are using conda:

https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/

Updating Python Package with setup.py

You can use editable installs with pip to install from your source and have it update as you make changes:

$ pip install -e .

What's the proper way to update Python packages when updating Python from 2.6 to 2.7?

First, you should not never ever ever ever install Python packages in in system library folder with easy_install using sudo on any operating system.

http://jamiecurle.co.uk/blog/installing-pip-virtualenv-and-virtualenvwrapper-on-os-x/#comment-573429347

The correct procedure would be make your installation procedure repeatable. There exist two commonly used solutions in Python world. These solutions automatically download correct versions of Python packages from http://pypi.python.org

PIP

pip and requirements.txt http://www.pip-installer.org/en/latest/requirements.html within virtualenv http://pypi.python.org/pypi/virtualenv

Buidout

Buildout, example from Plone CMS https://github.com/plone/Installers-UnifiedInstaller/blob/master/base_skeleton/versions.cfg

Buildout can also do configure, make, make install style installations for packages which need native libraries. For example there exist solution for libxml2 + lxml

http://pypi.python.org/pypi/z3c.recipe.staticlxml/

(Note: buildout does not need virtualenv as it does its own isolation from system Python)

How to make Python package update within a code to take effect on-the-fly

If you are able to, a simple solution would be to write a bash file running sequentially two python files, with a change of version of the package pyscenic between the two python runs using pip. You can do something similar to this, like:

#!/usr/bin/env bash
pip install pyscenic==0.10.0
python first_script.py
pip install pyscenic==0.10.4
python second_script.py


Related Topics



Leave a reply



Submit