Code Monkey home page Code Monkey logo

Comments (9)

karthiknadig avatar karthiknadig commented on May 22, 2024

@john1997x Can you run the command from the terminal? This looks like an issue with autopep8 itself or the encoding used to save the file (the file should be saved as UTF-8).

> set PYTHONPATH=c:\Users\joaop.vscode\extensions\ms-python.autopep8-2023.2.0\bundled\libs
> type <python-file-to-format> | c:\Users\joaop.pyenv\pyenv-win\versions\3.7.9\python.exe -m autopep8 --max-line-length=250 -

Make sure to include the - at the end in the second command.

from vscode-autopep8.

Howard-WeiKai avatar Howard-WeiKai commented on May 22, 2024

similar problem when autopep8 formatting

log:

2023-05-25 11:16:33.900 [info] [Trace - 上午11:16:33] Received response 'textDocument/formatting - (2)' in 354ms.
2023-05-25 11:16:37.022 [info] [Trace - 上午11:16:37] Sending request 'textDocument/formatting - (3)'.
2023-05-25 11:16:37.027 [info] [Trace - 上午11:16:37] Received notification 'window/logMessage'.
2023-05-25 11:16:37.027 [info] c:\Users\jhele\AppData\Local\Programs\Python\Python310\python.exe -m autopep8 -
2023-05-25 11:16:37.027 [info] [Trace - 上午11:16:37] Received notification 'window/logMessage'.
2023-05-25 11:16:37.027 [info] CWD Server: c:\Users\jhele\Desktop\p2p_orm
2023-05-25 11:16:37.290 [info] [Trace - 上午11:16:37] Received notification 'window/logMessage'.
2023-05-25 11:16:37.290 [info] Traceback (most recent call last):
File "c:\Users\jhele\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\Users\jhele\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\jhele.vscode\extensions\ms-python.autopep8-2023.4.0\bundled\libs\autopep8.py", line 4570, in
sys.exit(main())
File "c:\Users\jhele.vscode\extensions\ms-python.autopep8-2023.4.0\bundled\libs\autopep8.py", line 4516, in main
wrap_output(sys.stdout, encoding=encoding).write(fixed_stdin)
UnicodeEncodeError: 'cp950' codec can't encode character '\udc93' in position 1638: illegal multibyte sequence

from vscode-autopep8.

Usercyk avatar Usercyk commented on May 22, 2024

Me too
I can use autopep8 without error in the terminal.

log:

2023-05-25 21:08:10.614 [info] [Trace - 21:08:10] Sending request 'textDocument/formatting - (6)'.
2023-05-25 21:08:10.620 [info] [Trace - 21:08:10] Received notification 'window/logMessage'.
2023-05-25 21:08:10.621 [info] d:\vscode\Pyside6\qt_env\Scripts\python.exe -m autopep8 -
2023-05-25 21:08:10.621 [info] [Trace - 21:08:10] Received notification 'window/logMessage'.
2023-05-25 21:08:10.622 [info] CWD Server: d:\vscode\Pyside6
2023-05-25 21:08:11.022 [info] [Trace - 21:08:11] Received notification 'window/logMessage'.
2023-05-25 21:08:11.022 [info] Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "d:\vscode\Pyside6\qt_env\Lib\site-packages\autopep8.py", line 4570, in
sys.exit(main())
^^^^^^
File "d:\vscode\Pyside6\qt_env\Lib\site-packages\autopep8.py", line 4516, in main
wrap_output(sys.stdout, encoding=encoding).write(fixed_stdin)
UnicodeEncodeError: 'gbk' codec can't encode character '\udcad' in position 303: illegal multibyte sequence
2023-05-25 21:08:11.022 [info] [Trace - 21:08:11] Received response 'textDocument/formatting - (6)' in 409ms.

from vscode-autopep8.

Usercyk avatar Usercyk commented on May 22, 2024

If I remove all the code with Chinese, I won't get this error.

from vscode-autopep8.

karthiknadig avatar karthiknadig commented on May 22, 2024

@Usercyk Can you share your environment variables?

from vscode-autopep8.

karthiknadig avatar karthiknadig commented on May 22, 2024

@Usercyk Can you also confirm if the encoding for your python file is utf-8? You should be able to see the encoding on your status bar.
image

from vscode-autopep8.

TeoDar avatar TeoDar commented on May 22, 2024

set PYTHONPATH=c:\Users\joaop.vscode\extensions\ms-python.autopep8-2023.2.0\bundled\libs

Has the same error. File encoding - UTF-8. Python 3.11.4 autopep8 upgraded.
image

from vscode-autopep8.

karthiknadig avatar karthiknadig commented on May 22, 2024

The issue is caused by a bug in autopep8 itself. hhatto/autopep8#685
Identified this issue here #104

from vscode-autopep8.

lanjia1028 avatar lanjia1028 commented on May 22, 2024

give a way to avoid the case:

change VS setting "files.encoding": "gbk" as same as the OS default encode .

or change OS default encode to utf-8.

the reason is
C:\Users\admin.vscode\extensions\ms-python.autopep8-2023.4.0\bundled\libs\autopep8.py
line 4511 : read_stdin = sys.stdin.read()
using OS default encode to read your code steam , it will be decoding wrong.

from vscode-autopep8.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.