3

We have an internal wiki and I want to use pywikibot to get some data from it. Installed it from pip but when I import it I get:

>>> import pywikibot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/pywikibot/__init__.py",
line 25, in <module>
from pywikibot.bot import (
  File "/usr/local/lib/python3.7/site-packages/pywikibot/bot.py", line
105, in <module>
    from pywikibot import config2 as config
  File "/usr/local/lib/python3.7/site-packages/pywikibot/config2.py",
line 373, in <module>
    base_dir = get_base_dir()
  File "/usr/local/lib/python3.7/site-packages/pywikibot/config2.py",
line 367, in get_base_dir
    raise RuntimeError(exc_text)

RuntimeError: No user-config.py found in directory '/vagrant'.

Looking here https://www.mediawiki.org/wiki/Manual:Pywikibot/Installation#Configure_Pywikibot

I see a reference to pwb.py, but that does not exist in /usr/local/lib/python3.7/site-packages/pywikibot.

What am I missing here?

Thanks!

Jon Nezbit
  • 323
  • 3
  • 12
Larry Martell
  • 3,526
  • 6
  • 40
  • 76

2 Answers2

3

Installing pywikibot from pip currently only installs the library part. The pwb.py and related console scripts are not included in the PyPI package. That means that you'll need to create the user-config.py manually or download the scripts in some other way. I believe most pywikibot users just clone the git repo. The general process would be something like this:

git clone https://github.com/wikimedia/pywikibot.git --depth 1
python3 -m pip install -U setuptools
python3 -m pip install -e pywikibot/
cd pywikibot/
python3 pwb.py generate_family_file.py https://url.to.your/wiki/api.php? mywikiname
python3 pwb.py generate_user_files.py
# follow the prompts
AXO
  • 8,198
  • 6
  • 62
  • 63
  • Is the format of the config file defined somewhere? – Larry Martell Aug 18 '20 at 03:03
  • Since you've mentioned that it's an internal wiki, it's not just the `user-config.py`, you'll also need a family file (the `generate_family_file.py` above does that for you). I'm saying you might have a hard time configuring them all correctly, but see: https://github.com/wikimedia/pywikibot/blob/master/user-config.py.sample – AXO Aug 18 '20 at 03:07
  • @LarryMartell Also https://www.mediawiki.org/wiki/Manual:Pywikibot/user-config.py has more in-depth instructions. – AXO Aug 18 '20 at 03:11
  • Thanks for the reply - this was very helpful. A couple more questions: 1. Is there any way to login with MFA? Our wiki requires either choosing a number from an authenticator app or using a userid and password and then entering a code which was texted. 2. Is there a way to get all pages within a category? – Larry Martell Aug 18 '20 at 23:40
  • These can be separate SO questions, but AFAK `pywikibot` currently only supports [BotPassword](https://www.mediawiki.org/wiki/API:Login#Method_1._login) and [OAuthen](https://www.mediawiki.org/wiki/Extension:OAuth), [clientlogin](https://www.mediawiki.org/wiki/API:Login#Method_2._clientlogin) works only if MFA is not active :( Once the setup is complete getting pages within a category would be easy: `Category(Site(), 'title').members()`. – AXO Aug 19 '20 at 02:55
1

Adding generate_family_file is in active development: https://gerrit.wikimedia.org/r/c/pywikibot/core/+/634544

The other two script will follow later I guess.

xqt
  • 38
  • 2