Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows10 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte #1663

Closed
fenchu opened this issue Sep 15, 2017 · 10 comments

Comments

@fenchu
Copy link

fenchu commented Sep 15, 2017

Steps to reproduce

Microsoft Windows 10 Pro,1703,64-bit

  1. Install https://www.python.org/ftp/python/3.6.2/python-3.6.2-amd64.exe, installs under c:\dist\python
  2. Open bash/powershell and do pip install pylint
  3. run pylint

There is no other python on the system. have tried reinstalling.

Current behavior

λ pylint
Traceback (most recent call last):
  File "c:\dist\python\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\dist\python\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\dist\python\Scripts\pylint.exe\__main__.py", line 9, in <module>
  File "c:\dist\python\lib\site-packages\pylint\__init__.py", line 13, in run_pylint
    Run(sys.argv[1:])
  File "c:\dist\python\lib\site-packages\pylint\lint.py", line 1254, in __init__
    linter.read_config_file()
  File "c:\dist\python\lib\site-packages\pylint\config.py", line 635, in read_config_file
    parser.readfp(fp)
  File "c:\dist\python\lib\configparser.py", line 763, in readfp
    self.read_file(fp, source=filename)
  File "c:\dist\python\lib\configparser.py", line 718, in read_file
    self._read(f, source)
  File "c:\dist\python\lib\configparser.py", line 1015, in _read
    for lineno, line in enumerate(fp, start=1):
  File "c:\dist\python\lib\codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
  File "c:\dist\python\lib\encodings\utf_8_sig.py", line 69, in _buffer_decode
    return codecs.utf_8_decode(input, errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

it is the same in powershell, any other python program works fine

Could it be some python2/python3 and utf-8 missmatch?

Expected behavior

Works fine in windows bash (ubuntu 16.04):

$ pylint --version
No config file found, using default configuration
pylint 1.7.2,
astroid 1.5.3
Python 3.6.2 (default, Aug  8 2017, 09:25:03)
[GCC 5.4.0 20160609]

pylint --version output

λ pip freeze | findstr "pylint"
pylint==1.7.2

@fenchu
Copy link
Author

fenchu commented Sep 15, 2017

λ pip3 install pylint
Requirement already satisfied: pylint in c:\dist\python\lib\site-packages
Requirement already satisfied: six in c:\dist\python\lib\site-packages (from pylint)
Requirement already satisfied: isort>=4.2.5 in c:\dist\python\lib\site-packages (from pylint)
Requirement already satisfied: astroid>=1.5.1 in c:\dist\python\lib\site-packages (from pylint)
Requirement already satisfied: colorama; sys_platform == "win32" in c:\dist\python\lib\site-packages (from pylint)
Requirement already satisfied: mccabe in c:\dist\python\lib\site-packages (from pylint)
Requirement already satisfied: lazy-object-proxy in c:\dist\python\lib\site-packages (from astroid>=1.5.1->pylint)
Requirement already satisfied: wrapt in c:\dist\python\lib\site-packages (from astroid>=1.5.1->pylint)

@PCManticore
Copy link
Contributor

I see that you are using a different encoding that the usual one, can you get the output of chcp? Unfortunately pylint is mostly UTF-8 based, so having a less than usual encoding might trip it up.

@PCManticore PCManticore added the Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine label Sep 15, 2017
@rogalski
Copy link
Contributor

Looks like it's an exception from reading pylintrc file. Do you have matching file somewhere in your env?

@sldsrg
Copy link

sldsrg commented Oct 13, 2017

In PowerShell session on Windows 10 command
pylint --generate-rcfile > $HOME/.pylintrc
produce .pylintrc file with UTF16 encoding, and cause aforementioned problem

@rogalski rogalski added not a bug and removed Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine labels Nov 1, 2017
@rogalski
Copy link
Contributor

rogalski commented Nov 1, 2017

For now I'll close it as not a bug - since we do not support non-standard encodings in rcfile right now.

I'm not sure whether pylint eventually is supposed to support non-ascii / non-utf8 rc files. To be determined...

@rogalski rogalski closed this as completed Nov 1, 2017
@jasonbu
Copy link

jasonbu commented Jan 19, 2018

run chcp 65001
before run pip install pylint
in cmd or powershell.
solved this issue with my win10.

@andresgarcia0313
Copy link

chcp 65001 && pip install pylint && chcp 866 && pip install pylint

https://ss64.com/nt/chcp.html

@tristanbrown
Copy link

I encountered this bug when generating the .pylintrc file as described by @sldsrg (done in Windows 10, in the VS Code Powershell terminal). The chcp 65001 solution did not work for me.

I was able to fix it by opening my .pylintrc file in Notepad++, choosing the UTF-8 encoding there, and then saving the file. After that, the .pylintrc file remains in the proper format while editing and saving in VS Code.

@candu
Copy link

candu commented Feb 1, 2019

You can specify the encoding in PowerShell with Out-File:

pylint --generate-rcfile | Out-File -Encoding utf8 .pylintrc

thomaschang710114 pushed a commit to scvisgoing/watchnow that referenced this issue Feb 18, 2019
重新產生一次並加上 utf-8 的參數免得它存成 big5 或其它編碼

pylint --generate-rcfile | Out-File -Encoding utf8 .pylintrc
參考 pylint-dev/pylint#1663

並且修正一些 __init__.py 的警告
@xiaoluolovestudy
Copy link

very useful, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants