You are browsing a read-only backup copy of Wikitech. The live site can be found at

PAWS/Python with Pip

From Wikitech-static
Revision as of 01:28, 28 August 2022 by imported>EpicPupper (create documentation, see phab:T219354)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Python is a popular language to use with PAWS. PAWS works great with default Python out-of-the-box, but what if you need to import PyPi packages?

At the start of your file, add the below code:

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

That's it! The next time you run the program, the package will be automatically installed. On subsequent runs, Pip will detect if a package is already up-to-date and installed, and skip downloading.