Jump to content

Manual:Pywikibot/安装

From mediawiki.org
This page is a translated version of the page Manual:Pywikibot/Installation and the translation is 94% complete.
Outdated translations are marked like this.
这个页面将帮助你开始使用Pywikibot。您可以在您的个人计算机、Toolforge或PAWS: A Web Shell上使用Pywikibot。
PAWS

PAWS: A Web Shell 是最简单的入门Pywikibot的方式。 不需要安装,使用一个网页即可提交命令。

在您的个人计算机上使用

下列手册将帮助您在个人计算机上安装和运行Pywikibot。以下是四个主要步骤:

Toolforge

Toolforge在维基媒体服务器上为您提供稳定的基础设施,在这里你可以持续或定期运行机器人。

安装Python

https://www.python.org/downloads/ 下载并安装Python。 一定要勾选安装向导底部的“将Python添加到系统PATH目录”! 这样,您仅需在任意命令行窗口输入python3,就可以使用Python了

如果您已经安装了Python,请检查您的Python版本是否符合Pywikibot的要求。在主控台(windows上可用命令提示符)运行python --version即可获取版本号。 若要查看是否已安装Python 3或其更高版本,请在控制台中运行python3 --version

Ubuntu 19.04及以上版本自带Python2,Python3两个版本。 Python2 默认使用终端命令 python 运行;要使用Python3,请使用终端命令 python3

目前运行机器人需要{{$1|Python 3.9 或更高版本}},不过推荐使用Python 3.10 或更高。 在Windows中,不要忘记修改环境变量PATH,以確保Python和pip能正确运行。

安装依赖

運行 Pywikibot 需要額外的套件。 執行以下命令來安裝這些套件:

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

针对Python3.7版本,还需要安装额外的包。 通过以下指令安装:

python3 -m pip install importlib_metadata

备用的MediaWiki标记解析器可以通过以下指令安装:

python3 -m pip install "wikitextparser>=0.47.5"

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

安装Pywikibot

python3 -m pip install pywikibot

如果您使用 pip,在下面的示例中请使用 pwb 而不是 python3 pwb.py

Alternatives

下载当前的Pywikibot stable分支:.tar.gz, .zip

解压下载的文件,例如解压到~/pywikibot%USERPROFILE%\pywikibot

又或者,您可以使用git客户端从Gerrit获取最新版本,参见手册:Pywikibot/Gerrit This is the recommended way for active bot operators and developers to use Pywikibot.

其它版本可在https://pywikibot.toolforge.org/找到。

更新Pywikibot

確保您的机器人框架是最新版本。新版本会连续发布,并在同一位置可用。

如果您正在使用git版本,您可以跳过这一节。 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.

解压新版本,並覆盖所有旧版本的文件。

配置Pywikibot

在类Unix系统(Linux/BSD/Solaris)上打开“终端”,或在Windows上打开“命令提示符”(一般在“Windows”系统或“所有应用”中的“附件”文件夹,或是开始菜单中的“所有程序”菜单中),并移動至您解压Pywikibot的目录。

类Unix(Linux/BSD/Solaris)系统
cd ~/core
Windows系统
c:
cd "%USERPROFILE%\pywikibot"

請将路径替换为您解压Pywikibot的路径。

继续输入以下命令以生成用户配置文件:

python3 pwb.py generate_user_files

根据提示来配置Pywikibot。 您将需要创建密码

最后运行以下命令以登录您的wiki:

python3 pwb.py login

在第三方wiki上使用

Pywikibot已經预先配置好了很多维基网站,但也许不適用於你想要處理的那一个。 查看Manual:Pywikibot/Use on third-party wikis 来確認如何为你自己處理的维基网站配置Pywikibot。

更多配置選項

Pywikibot提供了许多选项来改变你的机器人行为。 您可以在user-config.py文件中修改这些选项。 参见config.py以获取您可以使用的所有参数列表。

代理服务器(Proxy)配置

Pywikibot使用requests与网络通信。 您可以使用环境变量HTTP_PROXYHTTPS_PROXY讓requests请求使用指定的代理服务器。 更多信息請见requests(请求)的文档

运行脚本

Pywikibot在scripts目录下储存了大量的脚本。 您可以通过以下指令运行它们:

python3 pwb.py [name of the script]

如需了解更多关于运行基础Pywikibot脚本的信息,可参阅:

所有脚本的列表可在Manual:Pywikibot/脚本 doc.wikimedia.org/pywikibot查看。

其他依赖性

大多数脚本不需要额外的依赖,但也有少部分没有安裝依赖就无法工作。 requirements.txt中列出了这些脚本及其依赖。

要为脚本安装其依赖,使用pip运行以下命令即可:

python3 -m pip install [name of the package]

或者,运行下面的命令来为所有脚本一次安装所有依赖:

python3 -m pip install -r requirements.txt


如果您需要更多关于设置您的Pywikibot的帮助,可以访问#pywikibot IRC频道 在线pywikibot@ 邮件列表