Listing Sage packages¶
This module can be used to see which Sage packages are installed and which packages are available for installation.
For more information about creating Sage packages, see the “Packaging Third-Party Code” section of the Sage Developer’s Guide.
Actually installing the packages should be done via the command line, using the following commands:
sage -i PACKAGE_NAME
– install the given packagesage -f PACKAGE_NAME
– re-install the given package, even if it was already installed
To list the packages available, either use in a terminal one of sage
-standard
, sage -optional
or sage -experimental
. Or the following
command inside Sage:
sage: from sage.misc.package import list_packages
sage: pkgs = list_packages(local=True)
sage: sorted(pkgs.keys()) # random
['4ti2',
'alabaster',
'arb',
...
'zlib',
'zn_poly',
'zope_interface']
Functions¶
-
exception
sage.misc.package.
PackageNotFoundError
¶ Bases:
exceptions.RuntimeError
This class defines the exception that should be raised when a function, method, or class cannot detect a Sage package that it depends on.
This exception should be raised with a single argument, namely the name of the package.
When a
PackageNotFoundError
is raised, this means one of the following:- The required optional package is not installed.
- The required optional package is installed, but the relevant interface to that package is unable to detect the package.
EXAMPLES:
sage: from sage.misc.package import PackageNotFoundError sage: raise PackageNotFoundError("my_package") Traceback (most recent call last): ... PackageNotFoundError: the package 'my_package' was not found. You can install it by running 'sage -i my_package' in a shell
-
sage.misc.package.
experimental_packages
()¶ DEPRECATED: use
list_packages()
Return two lists. The first contains the installed and the second contains the not-installed experimental packages that are available from the Sage repository.
OUTPUT:
- installed experimental packages (as a list)
- NOT installed experimental packages (as a list)
Run
sage -i package_name
from a shell to install a given package orsage -f package_name
to re-install it.EXAMPLE:
sage: from sage.misc.package import experimental_packages sage: installed, not_installed = experimental_packages()
-
sage.misc.package.
install_package
(package=None, force=None)¶ This function is obsolete. Run
sage -i PKGNAME
from a shell to install a package. Use the functioninstalled_packages()
to list all installed packages.TESTS:
sage: install_package() doctest:...: DeprecationWarning: use installed_packages() to list all installed packages See http://trac.sagemath.org/16759 for details. [...'arb...'python...] sage: install_package("autotools") Traceback (most recent call last): ... NotImplementedError: installing Sage packages using 'install_package()' is obsolete. Run 'sage -i autotools' from a shell prompt instead
-
sage.misc.package.
installed_packages
(exclude_pip=True)¶ Return a dictionary of all installed packages, with version numbers.
INPUT:
exclude_pip
– (optional, default:True
) whether “pip” packages are excluded from the list
EXAMPLES:
sage: installed_packages() {...'arb': ...'pynac': ...}
See also
-
sage.misc.package.
is_package_installed
(package, exclude_pip=True)¶ Return whether (any version of)
package
is installed.INPUT:
package
– the name of the packageexclude_pip
– (optional, default:True
) whether to consider pip type packages
EXAMPLES:
sage: is_package_installed('pari') True
Giving just the beginning of the package name is not good enough:
sage: is_package_installed('matplotli') False
Otherwise, installing “pillow” would cause this function to think that “pil” is installed, for example.
Check that the option
exclude_pip
is turned on by default:sage: from sage.misc.package import list_packages sage: for pkg in list_packages('pip', local=True): ....: assert not is_package_installed(pkg)
-
sage.misc.package.
list_packages
(*pkg_types, **opts)¶ Return a dictionary of information about each package.
The keys are package names and values are dictionaries with the following keys:
'type'
: either'standard'
,'optional'
,'experimental'
or'pip'
'installed'
: boolean'installed_version'
:None
or a string'remote_version'
: string
INPUT:
pkg_types
– (optional) a sublist of'standard'
,'optional'
,'experimental'
or'pip'
. If provided, list only the packages with the given type(s), otherwise list all packages.local
– (optional, default:False
) if set toTrue
, then do not consult remote (PyPI) repositories for package versions (only applicable for'pip'
type)exclude_pip
– (optional, default:False
) if set toTrue
, then pip packages are not considered.ignore_URLError
– (default:False
) if set toTrue
, then connection errors will be ignored
EXAMPLES:
sage: from sage.misc.package import list_packages sage: L = list_packages('standard') sage: sorted(L.keys()) # random ['alabaster', 'arb', 'babel', ... 'zn_poly', 'zope_interface'] sage: L['ppl'] {'installed': True, 'installed_version': '...', 'remote_version': '...', 'type': 'standard'} sage: L = list_packages('pip', local=True) sage: L['beautifulsoup'] {'installed': ..., 'installed_version': ..., 'remote_version': None, 'type': 'pip'} sage: L = list_packages('pip') # optional - internet sage: L['beautifulsoup'] # optional - internet {'installed': ..., 'installed_version': ..., 'remote_version': u'...', 'type': 'pip'}
Check the option
exclude_pip
:sage: list_packages('pip', exclude_pip=True) {}
-
sage.misc.package.
optional_packages
()¶ DEPRECATED: use
list_packages()
Return two lists. The first contains the installed and the second contains the not-installed optional packages that are available from the Sage repository.
OUTPUT:
- installed optional packages (as a list)
- NOT installed optional packages (as a list)
Run
sage -i package_name
from a shell to install a given package orsage -f package_name
to re-install it.EXAMPLE:
sage: from sage.misc.package import optional_packages sage: installed, not_installed = optional_packages() sage: 'ore_algebra' in installed+not_installed True sage: 'beautifulsoup' in installed+not_installed True sage: 'beautifulsoup' in installed # optional - beautifulsoup True sage: 'ore_algebra' in installed # optional - ore_algebra True
-
sage.misc.package.
package_versions
(package_type, local=False)¶ DEPRECATED: use
list_packages()
Return version information for each Sage package.
INPUT:
package_type
– (string) one of"standard"
,"optional"
or"experimental"
local
– (boolean, default:False
) only query local data (no internet needed)
For packages of the given type, return a dictionary whose entries are of the form
'package': (installed, latest)
, whereinstalled
is the installed version (orNone
if not installed) andlatest
is the latest available version. If the package has a directory inSAGE_ROOT/build/pkgs/
, thenlatest
is determined by the filepackage-version.txt
in that directory. Iflocal
isFalse
, then Sage’s servers are queried for package information.EXAMPLES:
sage: std = package_versions('standard', local=True) sage: 'gap' in std True sage: std['zn_poly'] ('0.9.p11', '0.9.p11')
-
sage.misc.package.
pip_installed_packages
()¶ Return a dictionary \(name->version\) of installed pip packages.
This command returns all pip-installed packages. Not only Sage packages.
EXAMPLES:
sage: from sage.misc.package import pip_installed_packages sage: d = pip_installed_packages() sage: 'scipy' in d True sage: d['scipy'] '...' sage: d['beautifulsoup'] # optional - beautifulsoup '...'
-
sage.misc.package.
pip_remote_version
(pkg, pypi_url='https://pypi.python.org/pypi', ignore_URLError=False)¶ Return the version of this pip package available on PyPI.
INPUT:
pkg
– the packagepypi_url
– (string, default: standard PyPI url) an optional Python package repository to useignore_URLError
– (default:False
) if set toTrue
then no error is raised if the connection fails and the function returnsNone
EXAMPLES:
The following test does fail if there is no TLS support (see e.g. trac ticket #19213):
sage: from sage.misc.package import pip_remote_version sage: pip_remote_version('beautifulsoup') # optional - internet # not tested u'...'
These tests are reliable since the tested package does not exist:
sage: nap = 'hey_this_is_NOT_a_python_package' sage: pypi = 'http://this.is.not.pypi.com/' sage: pip_remote_version(nap, pypi_url=pypi, ignore_URLError=True) # optional - internet doctest:...: UserWarning: failed to fetch the version of pkg='hey_this_is_NOT_a_python_package' at http://this.is.not.pypi.com/ sage: pip_remote_version(nap, pypi_url=pypi, ignore_URLError=False) # optional - internet Traceback (most recent call last): ... HTTPError: HTTP Error 404: Not Found
-
sage.misc.package.
pkgname_split
(name)¶ Split a pkgname into a list of strings, ‘name, version’.
For some packages, the version string might be empty.
EXAMPLES:
sage: from sage.misc.package import pkgname_split sage: pkgname_split('hello_world-1.2') ['hello_world', '1.2']
-
sage.misc.package.
standard_packages
()¶ DEPRECATED: use
list_packages()
Return two lists. The first contains the installed and the second contains the not-installed standard packages that are available from the Sage repository.
OUTPUT:
- installed standard packages (as a list)
- NOT installed standard packages (as a list)
Run
sage -i package_name
from a shell to install a given package orsage -f package_name
to re-install it.EXAMPLE:
sage: from sage.misc.package import standard_packages sage: installed, not_installed = standard_packages() sage: installed[0], installed[-1] ('alabaster', 'zope_interface')
-
sage.misc.package.
upgrade
()¶ Obsolete function, run
sage --upgrade
from a shell prompt instead.TESTS:
sage: upgrade() Traceback (most recent call last): ... NotImplementedError: upgrading Sage using 'upgrade()' is obsolete. Run 'sage --upgrade' from a shell prompt instead