Page MenuHomePhabricator

pywikibot configuration does not work
Closed, ResolvedPublic

Description

I followed the steps in :wikitech:Help:Toolforge/Pywikibot#Using_the_shared_Pywikibot_files_(recommended_setup).

But when I run
tools.tool@tools-login$ python /data/project/shared/pywikibot/core/generate_user_files.py
I get

tools.svgworkaroundbot@tools-sgebastion-07:~$ python /data/project/shared/pywikibot/core/generate_user_files.py
Traceback (most recent call last):
  File "/data/project/shared/pywikibot/core/generate_user_files.py", line 21, in <module>
    from pywikibot.tools import file_mode_checker
  File "/mnt/nfs/labstore-secondary-tools-project/pywikibot/public_html/core/pywikibot/__init__.py", line 24, in <module>
    from pywikibot.bot import (
  File "/mnt/nfs/labstore-secondary-tools-project/pywikibot/public_html/core/pywikibot/bot.py", line 98, in <module>
    from pywikibot import config2 as config
  File "/mnt/nfs/labstore-secondary-tools-project/pywikibot/public_html/core/pywikibot/config2.py", line 392, in <module>
    base_dir = get_base_dir()
  File "/mnt/nfs/labstore-secondary-tools-project/pywikibot/public_html/core/pywikibot/config2.py", line 386, in get_base_dir
    raise RuntimeError(exc_text)
RuntimeError: No user-config.py found in directory '/mnt/nfs/labstore-secondary-tools-project/svgworkaroundbot'.
  Please check that user-config.py is stored in the correct location.
  Directory where user-config.py is searched is determined as follows:

    Return the directory in which user-specific information is stored.

    This is determined in the following order:
     1.  If the script was called with a -dir: argument, use the directory
         provided in this argument.
     2.  If the user has a PYWIKIBOT_DIR environment variable, use the value
         of it.
     3.  If user-config is present in current directory, use the current
         directory.
     4.  If user-config is present in pwb.py directory, use that directory
     5.  Use (and if necessary create) a 'pywikibot' folder under
         'Application Data' or 'AppData\Roaming' (Windows) or
         '.pywikibot' directory (Unix and similar) under the user's home
         directory.

    Set PYWIKIBOT_NO_USER_CONFIG=1 to disable loading user-config.py

    @param test_directory: Assume that a user config file exists in this
        directory. Used to test whether placing a user config file in this
        directory will cause it to be selected as the base directory.
    @type test_directory: str or None
    @rtype: str

tools.svgworkaroundbot@tools-sgebastion-07:~$

Zhuyifei1999 wrote at https://commons.wikimedia.org/wiki/User_talk:SVGWorkaroundBot#Pywikibot

This looks like a bug from some recent pywikibot change.

Event Timeline

Change 500389 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] Revert "[bugfix] Fix error thrown on saving user-passwords.py"

https://gerrit.wikimedia.org/r/500389

Xqt claimed this task.

Change 500389 merged by jenkins-bot:
[pywikibot/core@master] Revert "[bugfix] Fix error thrown on saving user-passwords.py"

https://gerrit.wikimedia.org/r/500389

Hi, I'm getting the same error following the same guide. Is this supposed to be fixed?

Works for me as follows:

tools.xqtools@tools-sgebastion-10:~$ core/pwb.py generate_user_files
You can abort at any time by pressing ctrl-c

Your default user directory is "/data/project/xqtools/.pywikibot"
user-config.py already exists in the target directory "/data/project/xqtools/.pywikibot".
Would you like to change the directory? ([Y]es, [n]o): n

Can you run pwb.py version to get version information about the installed Pywikibot release and describe the steps you have made and it's results.

I don't seem to have the core files in my project:

tools.ims-bot@tools-sgebastion-10:~$ ls -a
.   .bash_history  .cloud-locale-test.skip  .python_history  .toolskube  logs		 situated-views.py
..  .bash_profile  .kube		    .pywikibot	     .viminfo	 replica.my.cnf

Running

python3 /data/project/shared/pywikibot/stable/pywikibot/scripts/version.py

as stated in the guide gives the same error. I just noticed this warning, but ain't sure what to do with it.

python3 /data/project/shared/pywikibot/core/pywikibot/scripts/generate_user_files.py

also fails, and editing .bash_profile with the new location didn't work either

As for my steps, I have followed the guide strictly:

become ims-bot
vim .bash_profile

inserted export PYTHONPATH=/data/project/shared/pywikibot/stable:/data/project/shared/pywikibot/stable/scripts

source .bash_profile
mkdir .pywikibot

then tried to set configs
python3 /data/project/shared/pywikibot/stable/pywikibot/scripts/generate_user_files.py

I also tried following this other guide with PYTHONPATH=/shared/pywikibot/core:/shared/pywikibot/core/externals/httplib2:/shared/pywikibot/core/scripts, same error

The reason I'm using Toolforge is because I have a script that runs for a few hours and PAWS normally disconnects during execution. I need geopandas which is a pain/impossible to install on Windows, so I tried setting up Pywikibot locally but ran into Skipped '/mnt/d/dev/core/user-config.py': writeable by others. both on WSL2 and Docker. Any recommendations appreciated, I won't be scheduling or running anything infinitely, it's an once-in-a-while thing to create and edit Wikidata pages...

I don't seem to have the core files in my project:

Yes because Pywikibot is located via symlink at /data/project/shared/pywikibot/stable. I've added two symlinks within my project, one for core and one for the stable release which points to /shared/pywikibot/core and /shared/pywikibot/stable. To call a script I use the pwb wrapper script:
core/pwb.py <scriptname> or stable/pwb.py <scriptname> but also a direct call works for me, e.g.
python3 /data/project/shared/pywikibot/core/pywikibot/scripts/version.py. So try again with the pwb.py wrapper; calling the version script should not check for the user_config.py.

inserted export PYTHONPATH=/data/project/shared/pywikibot/stable:/data/project/shared/pywikibot/stable/scripts

I also have this but i am not sure if this is necessary

also tried following this other guide with
PYTHONPATH=/shared/pywikibot/core:/shared/pywikibot/core/externals/httplib2:/shared/pywikibot/core/scripts, same error

the httplib2 path is surely outdated; it was for Pywikibot 1.0

If you still get a traceback please file it here because there where a lot of changes since 2019.

Ah OK, python3 /data/project/shared/pywikibot/core/pwb.py generate_user_files works, many thanks. Should I update the guide with this instruction?

I am now facing another issue: in the guide, one cds to $HOME/pywikibot in order to install dependencies. Since I'm using the shared files, I'm unsure where I should install them. cding to where the core files are gives me

WARNING: pywikibot 8.0.0.dev0 does not provide the extra 'geopandas'
WARNING: pywikibot 8.0.0.dev0 does not provide the extra 'openpyxl'
WARNING: pywikibot 8.0.0.dev0 does not provide the extra 'pandas'
WARNING: pywikibot 8.0.0.dev0 does not provide the extra 'requests'
WARNING: pywikibot 8.0.0.dev0 does not provide the extra 'tqdm'
WARNING: pywikibot 8.0.0.dev0 does not provide the extra 'xlrd'

Not cding at all fails since $HOME is not a Python project. Also, toolforge-jobs uses a Python3.9 image, but running python3 -m venv pwbvenv in the bash script creates a 3.7 environment. So if I manually activate it and install packages, these aren't found by the toolforge job executor later on. Or at least thats what I understand...

Should I update the guide with this instruction?

That would be great. I haven’t found the time to do it myself. The auxiliary scripts were relocated since 7.0 and the best way to use it is the pwb.py wrapper.

I am now facing another issue

I am not very familiar with toolforge and have no glue here. @Legoktm: can you help?

@Xqt do you have a virtual environment at all? Would you mind sharing your project folder structure? I still couldn't get this to work... Also confused by why I need the .pywikibot dir if my generated files went to $HOME...

@Martimpassos: can this be closed after T134495 clearification?