question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Printing log message when overwriting file triggers UnicodeEncodeError

See original GitHub issue

Describe the bug On Windows 10 (Powershell): When pipx upgrade overwrites a file it prints a log message. This triggers an exception.

How to reproduce Run pipx upgrade --include-injected <package> on Windows Powershell when a file needs to be overwritten.

See output below:

pipx upgrade --include-injected jupyterlab
⚠️  Overwriting file C:\Users\dwales\.local\bin\jlpm.exe with C:\Users\dwales\.local\pipx\venvs\jupyterlab\Scripts\jlpm.exe
--- Logging error ---
Traceback (most recent call last):
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\logging\__init__.py", line 1084, in emit
    stream.write(msg + self.terminator)
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 36-37: character maps to <undefined>
Call stack:
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\dwales\AppData\Local\Programs\Python\Python38\Scripts\pipx.exe\__main__.py", line 7, in <module>
    sys.exit(cli())
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\main.py", line 759, in cli
    return run_pipx_command(parsed_pipx_args)
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\main.py", line 216, in run_pipx_command
    return commands.upgrade(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\upgrade.py", line 160, in upgrade
    _ = _upgrade_venv(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\upgrade.py", line 125, in _upgrade_venv
    versions_updated += _upgrade_package(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\upgrade.py", line 50, in _upgrade_package
    expose_apps_globally(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\common.py", line 56, in expose_apps_globally
    _copy_package_apps(local_bin_dir, app_paths, suffix=suffix)
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\common.py", line 95, in _copy_package_apps
    logger.warning(f"{hazard}  Overwriting file {str(dest)} with {str(src)}")
Message: '⚠️  Overwriting file C:\\Users\\dwales\\.local\\bin\\jlpm.exe with C:\\Users\\dwales\\.local\\pipx\\venvs\\jupyterlab\\Scripts\\jlpm.exe'
Arguments: ()
⚠️  Overwriting file C:\Users\dwales\.local\bin\jupyter-lab.exe with C:\Users\dwales\.local\pipx\venvs\jupyterlab\Scripts\jupyter-lab.exe
--- Logging error ---
Traceback (most recent call last):
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\logging\__init__.py", line 1084, in emit
    stream.write(msg + self.terminator)
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 36-37: character maps to <undefined>
Call stack:
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\runpy.py", line 194, in _run_module_as_main
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\dwales\AppData\Local\Programs\Python\Python38\Scripts\pipx.exe\__main__.py", line 7, in <module>
    sys.exit(cli())
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\main.py", line 759, in cli
    return run_pipx_command(parsed_pipx_args)
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\main.py", line 216, in run_pipx_command
    return commands.upgrade(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\upgrade.py", line 160, in upgrade
    _ = _upgrade_venv(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\upgrade.py", line 125, in _upgrade_venv
    versions_updated += _upgrade_package(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\upgrade.py", line 50, in _upgrade_package
    expose_apps_globally(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\common.py", line 56, in expose_apps_globally
    _copy_package_apps(local_bin_dir, app_paths, suffix=suffix)
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\common.py", line 95, in _copy_package_apps
    logger.warning(f"{hazard}  Overwriting file {str(dest)} with {str(src)}")
Message: '⚠️  Overwriting file C:\\Users\\dwales\\.local\\bin\\jupyter-lab.exe with C:\\Users\\dwales\\.local\\pipx\\venvs\\jupyterlab\\Scripts\\jupyter-lab.exe'
Arguments: ()
⚠️  Overwriting file C:\Users\dwales\.local\bin\jupyter-labextension.exe with C:\Users\dwales\.local\pipx\venvs\jupyterlab\Scripts\jupyter-labextension.exe
--- Logging error ---
Traceback (most recent call last):
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\logging\__init__.py", line 1084, in emit
    stream.write(msg + self.terminator)
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 36-37: character maps to <undefined>
Call stack:
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\dwales\AppData\Local\Programs\Python\Python38\Scripts\pipx.exe\__main__.py", line 7, in <module>
    sys.exit(cli())
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\main.py", line 759, in cli
    return run_pipx_command(parsed_pipx_args)
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\main.py", line 216, in run_pipx_command
    return commands.upgrade(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\upgrade.py", line 160, in upgrade
    _ = _upgrade_venv(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\upgrade.py", line 125, in _upgrade_venv
    versions_updated += _upgrade_package(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\upgrade.py", line 50, in _upgrade_package
    expose_apps_globally(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\common.py", line 56, in expose_apps_globally
    _copy_package_apps(local_bin_dir, app_paths, suffix=suffix)
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\common.py", line 95, in _copy_package_apps
    logger.warning(f"{hazard}  Overwriting file {str(dest)} with {str(src)}")
Message: '⚠️  Overwriting file C:\\Users\\dwales\\.local\\bin\\jupyter-labextension.exe with C:\\Users\\dwales\\.local\\pipx\\venvs\\jupyterlab\\Scripts\\jupyter-labextension.exe'
Arguments: ()
⚠️  Overwriting file C:\Users\dwales\.local\bin\jupyter-labhub.exe with C:\Users\dwales\.local\pipx\venvs\jupyterlab\Scripts\jupyter-labhub.exe
--- Logging error ---
Traceback (most recent call last):
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\logging\__init__.py", line 1084, in emit
    stream.write(msg + self.terminator)
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 36-37: character maps to <undefined>
Call stack:
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\dwales\AppData\Local\Programs\Python\Python38\Scripts\pipx.exe\__main__.py", line 7, in <module>
    sys.exit(cli())
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\main.py", line 759, in cli
    return run_pipx_command(parsed_pipx_args)
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\main.py", line 216, in run_pipx_command
    return commands.upgrade(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\upgrade.py", line 160, in upgrade
    _ = _upgrade_venv(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\upgrade.py", line 125, in _upgrade_venv
    versions_updated += _upgrade_package(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\upgrade.py", line 50, in _upgrade_package
    expose_apps_globally(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\common.py", line 56, in expose_apps_globally
    _copy_package_apps(local_bin_dir, app_paths, suffix=suffix)
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\common.py", line 95, in _copy_package_apps
    logger.warning(f"{hazard}  Overwriting file {str(dest)} with {str(src)}")
Message: '⚠️  Overwriting file C:\\Users\\dwales\\.local\\bin\\jupyter-labhub.exe with C:\\Users\\dwales\\.local\\pipx\\venvs\\jupyterlab\\Scripts\\jupyter-labhub.exe'
Arguments: ()

Expected behavior The warning message should be printed without triggering an exception.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Mar 16, 2021

Thank you for fixing it! I’m enjoying using pipx as a lightweight alternative to Conda.

1reaction
ghostcommented, Mar 16, 2021
pipx install -e pycowsay
⚠️  Ignoring --editable install option. pipx disallows it for anything but a local path, to avoid having to create a new src/ directory.
--- Logging error ---
Traceback (most recent call last):
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\logging\__init__.py", line 1084, in emit
    stream.write(msg + self.terminator)
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 46-47: character maps to <undefined>
Call stack:
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\dwales\AppData\Local\Programs\Python\Python38\Scripts\pipx.exe\__main__.py", line 7, in <module>
    sys.exit(cli())
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\main.py", line 759, in cli
    return run_pipx_command(parsed_pipx_args)
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\main.py", line 191, in run_pipx_command
    return commands.install(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\commands\install.py", line 60, in install
    venv.install_package(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\venv.py", line 223, in install_package
    (package_or_url, pip_args) = parse_specifier_for_install(
  File "c:\users\dwales\appdata\local\programs\python\python38\lib\site-packages\pipx\package_specifier.py", line 147, in parse_specifier_for_install
    logger.warning(
Message: '⚠️  Ignoring --editable install option. pipx disallows it for anything but a local path, to avoid having to create a new src/ directory.'
Arguments: ()
  installed package pycowsay 0.0.0.1, Python 3.8.7
  These apps are now globally available
    - pycowsay.exe
done! ✨ 🌟 ✨
Read more comments on GitHub >

github_iconTop Results From Across the Web

Redirecting python output to a file causes ... - Stack Overflow
Windows Python should not know if it is writing to a console or the output is redirected/pipelined. Using Unicode API (ending with W,...
Read more >
How to solve unicode encoding issues - Invivoo
In ths new article, our expert will explain you how to solve unicode encoding issues. If you have any question, don't hesite to...
Read more >
Your Guide to the Python print() Function
In this step-by-step tutorial, you'll learn about the print() function in Python and discover some of its lesser-known features.
Read more >
warnings — Warning control — Python 3.11.1 documentation
The printing of warning messages is done by calling showwarning() , which may be overridden; the default implementation of this function formats the...
Read more >
Masquerading: Right-to-Left Override, Sub-technique T1036.002
RTLO is a non-printing Unicode character that causes the text that follows it to be displayed in reverse. For example, a Windows screensaver...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found