Zum Inhalt springen

Manual:Pywikibot/Installation

Aus MediaWiki
This page will help you get started with Pywikibot, either on your own computer, on Toolforge, or using PAWS: A Web Shell.
On PAWS

PAWS: A Web Shell is the easiest way to get started with Pywikibot. No installation is necessary, and you use a web interface to submit commands.

On your own computer

Below is a manual to help you set Pywikibot up and running on your own computer. There are four main steps to this process:

Toolforge provides you with a stable cloud infrastructure on Wikimedia servers that allows you to run bots continuously or on a schedule.

Install Python

[Bearbeiten]

Download and install Python from https://www.python.org/downloads/. Make absolutely certain that you check the box at the bottom of the install wizard asking if you want to add Python to PATH! That will allow you to access Python from any command prompt just by typing the keyword python.

If you already have Python installed, check if your version is recent enough by running python --version in a console. To discover if Python version 3 or above is installed, run python3 --version in a console.

Ubuntu 19.04 and up comes with versions 2 & 3 installed. Python v2 runs by default using terminal command python; to use v3, use terminal command python3.

Python 3.7 or higher is currently required to run the bot, but Python 3.8 or higher is recommended. On Windows please do not forget to modify PATH environment variable to make Python and pip work properly.

Install dependencies

[Bearbeiten]

Additional packages are required to run Pywikibot. Run the following command to install these packages:

$ python -m pip install "requests>=2.20.1"
$ python -m pip install "mwparserfromhell>=0.5.2"
$ python -m pip install packaging

For Python 3.7 an additional package is required. Install it with:

$ python -m pip install importlib_metadata

An alternate MediaWiki markup parser may be installed with:

$ python -m pip install "wikitextparser>=0.47.5"

See also https://doc.wikimedia.org/pywikibot/stable/introduction.html#quick-start


Install Pywikibot

[Bearbeiten]
$ python -m pip install pywikibot

If using pip, use pwb instead of python pwb.py in examples below.

Download current Pywikibot stable branch: .tar.gz, .zip.

Unpack downloaded file, for example in ~/pywikibot or %USERPROFILE%\pywikibot.

Alternatively, you may retrieve the latest version using git or svn client from Gerrit, see Manual:Pywikibot/Gerrit . This is the recommended way for active bot operators and developers to use Pywikibot.

Other versions are available at https://pywikibot.toolforge.org/.

Updating Pywikibot

[Bearbeiten]

Keep your bot framework up to date. New versions are released continuously, and are available at the same location.

If you are using git or svn release, you may skip this note. Otherwise please be aware of a necessity to backup your configuration files and scripts (user-config.py, any family file, or custom script that you might have created or changed, and any current XML dump file you're using for a wiki) before installing a new release.

Unpack the new version over the old version, overwriting all files.

Configure Pywikibot

[Bearbeiten]

Open Terminal on Unix-like (Linux/BSD/Solaris) or Command Prompt on Windows (typically under Windows System or Accessories folders in All apps or All programs menu inside the Start menu), and change directory to where you unpacked Pywikibot:

Unix-like (Linux/BSD/Solaris):
$ cd ~/core
Windows:
$ c:
$ cd "%USERPROFILE%\pywikibot"

Substitute the location to where you unpacked Pywikibot.

Continue with the following command to generate user configuration file:

$ python pwb.py generate_user_files

Follow the prompts to configure Pywikibot.

Finally run the following command to log in to your wiki:

$ python pwb.py login

Use on third-party wikis

[Bearbeiten]

Pywikibot is pre-configured for a large number of wikis, but possibly not for the one you want to work on. See Manual:Pywikibot/Use on third-party wikis for how to configure Pywikibot for your wiki.

More configuration options

[Bearbeiten]

Pywikibot provides a wide range of configuration options to change the behavior of your bot. You can change these settings in the file user-config.py. See config.py for a list of all parameters you can use.

Proxy configuration

[Bearbeiten]

Pywikibot relies on requests for communicating with the web. You can use HTTP_PROXY and HTTPS_PROXY environment variables to make requests use a proxy server. Refer to requests' documentation for more info.

Run a script

[Bearbeiten]

Pywikibot comes packaged with a large number of scripts in the scripts directory. You can run all of these using:

$ python pwb.py [name of the script]

To learn more about running basic Pywikibot scripts, see:

A list of all scripts is available at Manual:Pywikibot/Scripts and doc.wikimedia.org/pywikibot.

Other dependencies

[Bearbeiten]

Most scripts do not require additional packages, but a few of them will not work without. These are listed in requirements.txt together with their dependencies.

To install dependencies for some script, use pip, and run the following command:

$ python -m pip install [name of the package]

Alternatively, run the following command to install all dependencies for all scripts at once:

$ python -m pip install -r requirements.txt


If you need more help on setting up your Pywikibot visit the #pywikibot IRC channel connect or pywikibot@ mailing list.