Manual talk:Pywikibot/Installation

From mediawiki.org
Latest comment: 4 months ago by LA2 in topic python 2 is gone
The following discussion has been transferred from Meta-Wiki.
Any user names refer to users of that site, who are not necessarily users of MediaWiki.org (even if they share the same username).

It has problems with python 2.7! And I don't understand how to install earlier version. thanks for helpers! Ofekalef 17:41, 18 May 2011 (UTC)Reply

Hi. I'm trying to install Pywikipedia, and have downloaded python, but when I go here, I see no link to 'download the latest pywiki zip file'. There is no zip file on that page. Can anyone help? Thanks, 81.151.38.162

Ah, it was a wrong link. Fixed. 81.151.38.162

Updating on Windows[edit]

I can't see that this page tells the user how to update the installation on Windows. Njardarlogar 14:44, 30 December 2011 (UTC)Reply

Yes Done  @xqt 13:12, 6 April 2014 (UTC)Reply

Core[edit]

The current installation instructions (whether by git or svn) gives me a directory called 'core'. It would make more sense if it was pywikibot or pywikibot-core. In previous years (before git), the SVN installation produced a directory named pywikipedia. It seems the current instructions assume I'm already in a directory named pywikibot, but this assumption is not spelled out. Having in my home directory a subdirectory named 'core' is not at all intuitive. --LA2 (talk) 01:55, 12 February 2014 (UTC)Reply

You may use your preferred directory name. pywikibot or pwb are also ok. Or something like pywikibot-core. I have a directory pwb containing both branches core and compat.  @xqt 13:17, 6 April 2014 (UTC)Reply

PYWIKIBOT_DIR[edit]

The instruction say to register an environment variable called PYWIKIBOT_DIR, but at least core check for PYWIKIBOT2_DIR environment variable.--Moroboshi (talk) 04:34, 13 June 2014 (UTC)Reply

Python versions on Windows[edit]

This manual currently suggests to install "the latest" 2.7.10 Python release for Windows.

Does this mean that core version would not work on any Windows version with any 3.x Python version? Suppose, things are much better.

It should also be noted that the latest Python 3.x version supported on Windows XP is 3.4.3, see SO#32491161.

--Olexa Riznyk (talk) 15:11, 8 November 2015 (UTC)Reply

3.x *should* work. If you try it, please let us know and update the manual :-) Legoktm (talk) 19:38, 9 November 2015 (UTC)Reply

Installation instruction errors[edit]

This has you change your python path to point to pywikibot but it really needs to point to core. Or core needs renamed. Going to change it unless somebody objects if anyone is watching this page. Lonjers (talk) 03:44, 16 December 2015 (UTC)Reply

Windows install unsuccessful[edit]

I followed the instructions, renaming the directory where my pywikibot installation is from c:\users\myUserName\core\core (that's right, core occurred twice in path) to c:\users\myUserName\pywikibot because it seemed to be what the instructions wanted. I didn't make any other change to compensate for this renaming.

I continued and did the step that says

> python pwb.py login

I received the error message

Traceback (most recent call last):
  File "pwb.py", line 185, in <module>
    import pywikibot
ImportError: No module named 'pywikibot'

Suggestions? Jc3s5h (talk) 21:30, 29 July 2017 (UTC)Reply

I found that if I used the git method of downloading pywikibot, it put it in a directory named C:\Users\myUserName\core and if I followed the directions using that directory, it worked. I'm not sure if it was not renaming the path to pywikibot, or using git rather than the zip file, that did the trick. Jc3s5h (talk) 22:44, 29 July 2017 (UTC)Reply

Several errors[edit]

The download appears to be broken. When trying to execute pwb.py in the pywikibot-folder, this file can not be found. In fact, it is in the upper core folder, but trying to execute it there also doesn't work. -- 188.23.125.244 00:00, 6 September 2017 (UTC)Reply

pwb.py is at the right place, it should be in the main directory. What’s the error if you try to execute pwb.py login from the command line? --Tacsipacsi (talk) 19:31, 7 September 2017 (UTC)Reply

pip + windows + python2 problems[edit]

I have windows 7 and Python 2.7.13 installed, but i can't run pip. I unpacked zip file in folder C:\core. When I run command pip install requests in same folder, command line gives me 'pip' is not recognized as an internal or external command, operable program or batch file. What did I do wrong? --BokicaK (talk) 02:43, 28 July 2018 (UTC)Reply

@BokicaK: pip has to be selected during the installation process. I recommend you to install the latest Python2 version, 2.7.15, and pay attention to select pip on the Customize Python page. —Tacsipacsi (talk) 10:36, 28 July 2018 (UTC)Reply
I installed Python 2.7.15 with pip, same happens. --BokicaK (talk) 19:16, 30 July 2018 (UTC)Reply
C:\core>pip install requests
'pip' is not recognized as an internal or external command,
operable program or batch file.

C:\core>pip install requests

--BokicaK (talk) 19:17, 30 July 2018 (UTC)Reply

Maybe it is missing in the PATH? --Dvorapa (talk) 04:37, 1 August 2018 (UTC)Reply
Good point, adding Python to PATH is disabled by default in the installer. You can change PATH manually at Control Panel → System and Security → System → Change settings (in the Computer name, domain, and workgroup settings section; it may ask for administrator password) → Advanced → Environment Variables → Path (System variables section). Just prepend C:\Python27\;C:\Python27\Scripts\; (or wherever you have installed Python) to it and restart the console window to take it affect. —Tacsipacsi (talk) 14:04, 1 August 2018 (UTC)Reply

I reinstaled python (twice), changed path, nothing has changed. Output is still: 'pip' is not recognized as an internal or external command, operable program or batch file. --BokicaK (talk) 16:50, 27 May 2019 (UTC)Reply

Disreagard, I reinstaled python third time with install Python.exe to PATH checked, now it works. --BokicaK (talk) 17:00, 27 May 2019 (UTC)Reply

Unable to configure pywikibot[edit]

I can't configure pywikibot. It is saying 'python' is not recognized as an internal or external command, operable program or batch file.' How to fix this? Pkbwcgs (talk) 17:05, 16 December 2018 (UTC)Reply

Have you installed Python from https://python.org? Pywikibot won’t run without it. —Tacsipacsi (talk) 21:59, 16 December 2018 (UTC)Reply
Also make sure you have Python in your PATH environment variable set correctly. On Windows you don't need to use python pwb.py script, you can just use pwb.py script. Some operating systems also use python2 or python3 commands instead of a python command. --Dvorapa (talk) 11:38, 15 March 2019 (UTC)Reply
As far as I remember, the Windows installer adds Python to PATH and sets file type association by default (maybe they’re opt-out options). And python2/python3 is not a Windows issue: on Windows, you don’t have two versions of Python installed, you have at least half a dozen. ;) Package dependency is a really good thing on Linux. (By the way, python is needed neither on Linux: ./pwb.py works fine because of the shebang.) —Tacsipacsi (talk) 19:58, 17 March 2019 (UTC)Reply

How to replace the text of a template with the updated text[edit]

Hello,

I am trying to write a script that updates the metainfo displayed in Youtube Info box(ie Infobox YouTube personality template). I have managed to get the updated template text using Youtube APIs and python scripts.

The only manual step that remains is to actually update the page. Is there a way to replace the contents of a particular template on a page with the updated content. --Maskaravivek (talk) 15:03, 11 March 2019 (UTC)Reply

Hello, you can use pywikibot/textlib.py, there are functions like extract_templates_with_params. It creates a list of templates and params in a given text. Then update the template you want, use glue_template_and_params to make it textual again and finally replace the original template with the new glued one e.g. by text slicing or using template regex pattern from the textlib.py. The second option you can use is scripts/template.py, in which you can find a TemplateRobot class, that compiles the textlib functions into an easy-to-use class. --Dvorapa (talk) 11:35, 15 March 2019 (UTC)Reply

Gerrit -> Phabricator[edit]

It appears the repo moved from Gerrit to Phabricator and is now located here: https : //phabricator . wikimedia . org/diffusion/PWBC/ (Remove spaces. I can't post a URL.)

On Phabricator it is just a mirror of Gerrit repo. --Dvorapa (talk) 07:58, 24 August 2019 (UTC)Reply

'user-config.py': writeable by others.[edit]

Got this error whith a local install. This is fixed my changing the read/write permission to read only: chmod 600 user-config.py --1Veertje (talk) 11:37, 30 October 2019 (UTC)Reply

This is a usual behavior, you have to have correct permissions on the file to make it work. --Dvorapa (talk) 20:22, 31 October 2019 (UTC)Reply

internal_api_error_Error when running a script[edit]

Hello, I have installed the latest pywikibot on a centos7 server (python3/pip3) and configured it to successfully log in to a bot account I have created on my private MW 34.x wiki (yay!), but when we try to run a basic script such as "add_text.py" I get an vague error message relating to the API. It's not a permissions error, I've solved that. Now it says, "ERROR: Detected MediaWiki API exception internal_api_error_Error". Can anyone please help me debug this? Here's the error:

[revansx@meza1 core_stable]$ python3 pwb.py login
Logged in on somewiki:en as MrBot.

[revansx@meza1 core_stable]$ python3 pwb.py add_text -cat:Some_Pages -text:'Hello World'
WARNING: API error internal_api_error_Error: [XqtN7LIvu8DlHjdVfQAmeQAAAAg] Caught exception of type Error
ERROR: Detected MediaWiki API exception internal_api_error_Error: [XqtN7LIvu8DlHjdVfQAmeQAAAAg] Caught exception of type Error
[errorclass: Error]; raising
Traceback (most recent call last):
  File "pwb.py", line 390, in <module>
    if not main():
  File "pwb.py", line 385, in main
    file_package)
  File "pwb.py", line 101, in run_python_file
    main_mod.__dict__)
  File "./scripts/add_text.py", line 360, in <module>
    main()
  File "./scripts/add_text.py", line 352, in main
    for page in generator:
  File "/home/revansx/core_stable/pywikibot/pagegenerators.py", line 1554, in CategorizedPageGenerator
    for a in category.articles(**kwargs):
  File "/home/revansx/core_stable/pywikibot/page/__init__.py", line 2983, in articles
    member_type=['page', 'file']
  File "/home/revansx/core_stable/pywikibot/tools/__init__.py", line 1790, in wrapper
    return obj(*__args, **__kw)
  File "/home/revansx/core_stable/pywikibot/site/__init__.py", line 4052, in categorymembers
    total=total, g_content=content, **cmargs)
  File "/home/revansx/core_stable/pywikibot/tools/__init__.py", line 1790, in wrapper
    return obj(*__args, **__kw)
  File "/home/revansx/core_stable/pywikibot/site/__init__.py", line 1943, in _generator
    gen = gen_class(type_arg, **req_args)
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 2921, in __init__
    QueryGenerator.__init__(self, **kwargs)
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 2456, in __init__
    self.site._paraminfo.fetch('query+' + mod for mod in self.modules)
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 395, in fetch
    self._init()
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 274, in _init
    self._fetch(self.preloaded_modules)
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 478, in _fetch
    result = request.submit()
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 2251, in submit
    self._data = super(CachedRequest, self).submit()
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 2040, in submit
    if self._internal_api_error(code, error, result):
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 1910, in _internal_api_error
    raise e
pywikibot.data.api.APIMWException: internal_api_error_Error: [XqtN7LIvu8DlHjdVfQAmeQAAAAg] Caught exception of type Error
[errorclass: Error]
CRITICAL: Exiting due to uncaught exception <class 'pywikibot.data.api.APIMWException'>
We've already answered you in the other talk page. --Dvorapa (talk) 08:15, 2 May 2020 (UTC)Reply

generate user files does nothing[edit]

Hi, I am working on a Windows PC and have already tried pywikibot with Python 3.6, and it seemed to work. I have switched to python 3.8 and tried to reinstall pywikibot, but I can't launch pwb.py generate_user_files. It just does nothing:

C:\Users\martin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.8\core_stable\pywikibot>python pwb.py generate_user_files 
C:\Users\martin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.8\core_stable\pywikibot>

Any idea on what it going on ? -Zolo (talk) 20:46, 14 August 2020 (UTC)Reply

new version on ubuntu bionic[edit]

Hi, I have ubuntu bionic, which has python2 and python3.6 installed, but defaults to python2. Anyone knows how I can configure pywikibot to use python3.6? 2A02:908:2F35:2FE0:84CF:D3D7:C7F2:1123 19:37, 18 September 2020 (UTC)Reply

OK, I managed to install it with "sudo apt-get install python3-dev python3-pip" then "pip3 install --upgrade pip setuptools" and "pip3 install "requests>=2.20.1"". Pywikibot now works, hoever I get errors: File "/usr/lib/python3.6/threading.py", line 1053, in join raise RuntimeError("cannot join current thread") RuntimeError: cannot join current thread. Any ideas? 2A02:908:2F35:2FE0:84CF:D3D7:C7F2:1123 20:27, 18 September 2020 (UTC)Reply

Correction to Configure Pywikibot section[edit]

Since the zip file expands pwb.py into ~/pywikibot/core (not ~/pywikibot), the first instruction in the Configure Pywikibot section should apparently read

$ cd ~/pywikibot/core

— Preceding unsigned comment added by MichaelMaggs (talkcontribs) 21:08, 21 November 2020 (UTC)Reply

Rework the whole documentation[edit]

I'm sorry to be so destructive in criticism, but I'm trying since a hour or so to install Pywikibot, failing miserably because every single step in this page is wrong, from prepending "python" to every line to the single command, to the point that even "login" doesn't work. Please, please, update e revisit the whole page. Sannita (talk) 17:11, 2 December 2020 (UTC)Reply

Everything worked fine in 2010. After that, idiots have taken over this project and destroyed it. --80.216.245.113 19:49, 3 October 2021 (UTC)Reply

How to run crontab On PAWS[edit]

I tried to use crontab in PAWS. but i got this error "bash: crontab: command not found". Any one of you, please guide.--Info-farmer (talk) 06:46, 15 January 2022 (UTC)Reply

@Info-farmer Unfortunately PAWS doesn't currently support running cron-like scheduled jobs. :/ Majavah (talk!) 11:18, 15 January 2022 (UTC)Reply

Install PWB instructions unclear[edit]

Hi, I was helping someone install PWB just now and I think the section "Install Pywikibot" is a bit unclear and could also use clarification. In particular, it's not clear to me if this represents 2 or 3 alternative paths. I believe that it's 3 options:

  1. Use pip
  2. Download the stable branch & unpack
  3. Use git

But as written, it looks like 2 options:

  1. Use pip AND THEN download the stable branch (which makes little sense)
  2. Use git

What's also missing imo is justifications for each reasoning. To me, PWB is a tool for mass wiki-editing. A pros-and-cons of each installation method would be welcome; for example, I can easily see why you would use git (e.g. if git is more familiar to you, but also if you wanted to have it under version control in the first place, e.g. if you plan to add any of your own scripts to the suite, and want to be able to make updates, you should certainly be using git). But I'm having trouble seeing the benefit of using pip. When would you want to do this? My use cases with PWB have been more limited as I see it only as a CLI tool, so maybe it also would sometimes be used as a library for other tooling? Might you do both 1 & 2?

Any clarifications would enrich the documentation significantly here I think. Thanks! RheingoldRiver (talk) 19:11, 24 February 2023 (UTC)Reply

python 2 is gone[edit]

The current instructions read "Ubuntu 19.04 and up comes with versions 2 & 3 installed." This is not true. I'm running Ubuntu 23.04 and it only has python3, not python (version 2).

The command "python3 -m pip install ..." gives "error: externally-managed-environment ..." Using "apt install ..." I can get requests and mwparserfromhell, but not wikitextparser and not pywikibot. LA2 (talk) 19:05, 15 December 2023 (UTC)Reply