Printing log message when overwriting file triggers UnicodeEncodeError
See original GitHub issueDescribe 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:
- Created 3 years ago
- Comments:14 (9 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for fixing it! I’m enjoying using pipx as a lightweight alternative to Conda.