Page MenuHomePhabricator

Unable to find editor for files *.py when using pywikibot as library
Closed, ResolvedPublic

Description

Installed pywikibot using pip (Metadata-Version: 2.0, Name: pywikibot, Version: 2.0rc5)
when running my own script with Python 3.5.1 containing

import pywikibot

I get

WARNING: Unable to find editor for files *.py
Traceback (most recent call last):
File "C:\Program Files (x86)\Python\lib\site-packages\pywikibot\config2.py", line 847, in _win32_extension_command
    '%s\shell\open\command' % _progID)
FileNotFoundError: [WinError 2] Systém nem\u016f\u017ee nalézt uveden\xfd soubor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "get_wd_query_results.py", line 1, in <module>
    import pywikibot
  File "C:\Program Files (x86)\Python\lib\site-packages\pywikibot\__init__.py", line 32, in <module>
    from pywikibot import config2 as config
  File "C:\Program Files (x86)\Python\lib\site-packages\pywikibot\config2.py", line 979, in <module>
    editor = _detect_win32_editor()
  File "C:\Program Files (x86)\Python\lib\site-packages\pywikibot\config2.py", line 872, in _detect_win32_editor
    editor = _win32_extension_command(ext)
  File "C:\Program Files (x86)\Python\lib\site-packages\pywikibot\config2.py", line 859, in _win32_extension_command
    print(e)
  File "C:\Program Files (x86)\Python\lib\encodings\cp437.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 23-24: character maps to <undefined>

Event Timeline

Wesalius renamed this task from Unable to find editor for files *.py when importing pywikibot to Unable to find editor for files *.py when using pywikibot as library.Sep 26 2016, 4:29 AM

when I move the script to "core" folder where pwb.py etc. is then it works

Xqt triaged this task as High priority.Sep 27 2016, 8:51 AM
Xqt added subscribers: valhallasw, jayvdb.

I don't understand how moving can solve this issue.

The main problem here is that Python thinks the console uses the cp437 charset, which is the IBM PC charset, rather than the cp895 Czech charset that one would expect on a Czech machine. We cannot use pywikibot.output (or pywikibot.exception) here yet, so I think we should just print repr(e) instead, as that would always be an ascii-only (albeit maybe not completely readable) form.

Wesalius claimed this task.

I dont have a good explanation, but I cleaned my system of all old python installations, cleaned out the system variables and installed python 3.5.2 and pywikibot library anew and everything now runs fine, the script executes without errors.