Jump to content

PAWS/Python with Pip

From Wikitech

PAWS works great with default Python out-of-the-box, but what if you need to import packages from PyPi?

At the start of your file, add code like:

import sys
!{sys.executable} -m pip install [PACKAGE]

Replace "[PACKAGE]" with the name of the package you want to import. For example, to use mwclient, a lightweight wrapper for the MediaWiki API:

import sys
!{sys.executable} -m pip install mwclient

The next time you run this cell of the notebook, the specified package will be automatically downloaded and installed. On subsequent runs, pip will detect if a package is already up-to-date and installed, and skip downloading.

Note packages are only temporarily installed on an ephemeral storage that is cleaned up every time your PAWS server is restarted.[1] To manually restart your server, go to your Hub Control Panel, hit Stop My Server and then start a new instance. Your notebooks and files won't be lost.

References

  1. Davis, B. (2025) Re: Python virtual environments in PAWS, 19 November 2025. Wikimedia Cloud Services mailing list.