Python is another encoding issue. Windows 8.1, both latest pythons. pip exception excludes

I have installed a clean new version of python on my Windows 8.1. I've tried Python 2.7.8 and Python 3.4.

I am running python get-pip.py from the command line - this installed pip correctly. I got this from here .

Then I run pont install mongo-connector. This loads the mongo connector and throws an exception like this:

Downloading/unpacking mongo-connector
  Downloading mongo-connector-1.3.tar.gz
  Running setup.py (path:c:\users\imon~1\appdata\local\temp\pip_build_èimon\mong
o-connector\setup.py) egg_info for package mongo-connector

Cleaning up...
Exception:
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "C:\Python27\lib\site-packages\pip\commands\install.py", line 278, in run

    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundl
e=self.bundle)
  File "C:\Python27\lib\site-packages\pip\req.py", line 1234, in prepare_files
    req_to_install.assert_source_matches_version()
  File "C:\Python27\lib\site-packages\pip\req.py", line 464, in assert_source_ma
tches_version
    % (display_path(self.source_dir), version, self))
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8a in position 55: ordinal
 not in range(128)

Traceback (most recent call last):
  File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\Scripts\pip.exe\__main__.py", line 9, in <module>
  File "C:\Python27\lib\site-packages\pip\__init__.py", line 185, in main
    return command.main(cmd_args)
  File "C:\Python27\lib\site-packages\pip\basecommand.py", line 161, in main
    text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8a in position 70: ordinal
 not in range(128)

      

In the case of Python 3.4, it throws:

Downloading/unpacking mongo-connector
  Downloading mongo-connector-1.3.tar.gz
Cleaning up...
Exception:
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "C:\Python34\lib\site-packages\pip\commands\install.py", line 278, in run

    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundl
e=self.bundle)
  File "C:\Python34\lib\site-packages\pip\req.py", line 1229, in prepare_files
    req_to_install.run_egg_info()
  File "C:\Python34\lib\site-packages\pip\req.py", line 292, in run_egg_info
    logger.notify('Running setup.py (path:%s) egg_info for package %s' % (self.s
etup_py, self.name))
  File "C:\Python34\lib\site-packages\pip\log.py", line 102, in notify
    self.log(self.NOTIFY, msg, *args, **kw)
  File "C:\Python34\lib\site-packages\pip\log.py", line 162, in log
    consumer.write(write_content)
  File "C:\Python34\lib\site-packages\pip\_vendor\colorama\ansitowin32.py", line
 116, in write
    self.write_and_convert(text)
  File "C:\Python34\lib\site-packages\pip\_vendor\colorama\ansitowin32.py", line
 143, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "C:\Python34\lib\site-packages\pip\_vendor\colorama\ansitowin32.py", line
 148, in write_plain_text
    self.wrapped.write(text[start:end])
  File "C:\Python34\lib\encodings\cp437.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u0160' in position
70: character maps to <undefined>

Traceback (most recent call last):
  File "C:\Python34\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python34\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python34\Scripts\pip.exe\__main__.py", line 9, in <module>
  File "C:\Python34\lib\site-packages\pip\__init__.py", line 185, in main
    return command.main(cmd_args)
  File "C:\Python34\lib\site-packages\pip\basecommand.py", line 168, in main
    logger.fatal('Storing debug log for failure in %s' % log_file_fn)
  File "C:\Python34\lib\site-packages\pip\log.py", line 111, in fatal
    self.log(self.FATAL, msg, *args, **kw)
  File "C:\Python34\lib\site-packages\pip\log.py", line 162, in log
    consumer.write(write_content)
  File "C:\Python34\lib\site-packages\pip\_vendor\colorama\ansitowin32.py", line
 116, in write
    self.write_and_convert(text)
  File "C:\Python34\lib\site-packages\pip\_vendor\colorama\ansitowin32.py", line
 140, in write_and_convert
    self.write_plain_text(text, cursor, start)
  File "C:\Python34\lib\site-packages\pip\_vendor\colorama\ansitowin32.py", line
 148, in write_plain_text
    self.wrapped.write(text[start:end])
  File "C:\Python34\lib\encodings\cp437.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u0160' in position
42: character maps to <undefined>

      

====

Running a simple pip without any parameters causes this:

Traceback (most recent call last):
  File "C:\Python34\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python34\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python34\Scripts\pip.exe\__main__.py", line 9, in <module>
  File "C:\Python34\lib\site-packages\pip\__init__.py", line 177, in main
    cmd_name, cmd_args = parseopts(initial_args)
  File "C:\Python34\lib\site-packages\pip\__init__.py", line 148, in parseopts
    parser.print_help()
  File "C:\Python34\lib\optparse.py", line 1646, in print_help
    file.write(self.format_help())
  File "C:\Python34\lib\encodings\cp437.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u0160' in position
1235: character maps to <undefined>

      

Running pip in Python 2.7.8 brings up the following:

Traceback (most recent call last):
  File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\Scripts\pip.exe\__main__.py", line 9, in <module>
  File "C:\Python27\lib\site-packages\pip\__init__.py", line 177, in main
    cmd_name, cmd_args = parseopts(initial_args)
  File "C:\Python27\lib\site-packages\pip\__init__.py", line 148, in parseopts
    parser.print_help()
  File "C:\Python27\lib\optparse.py", line 1670, in print_help
    file.write(self.format_help().encode(encoding, "replace"))
  File "C:\Python27\lib\encodings\cp437.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8a in position 1210: ordin
al not in range(128)

      

This has never happened on any other machine I have used. I found many similar problems, but none of them related to what I need to do with my case.

This thread tells me to run chcp 65001. When I do this and run pip afterwards, it outputs the following:

C:\Python27\Scripts>pip
Traceback (most recent call last):
  File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\Scripts\pip.exe\__main__.py", line 9, in <module>
  File "C:\Python27\lib\site-packages\pip\__init__.py", line 177, in main
    cmd_name, cmd_args = parseopts(initial_args)
  File "C:\Python27\lib\site-packages\pip\__init__.py", line 148, in parseopts
    parser.print_help()
  File "C:\Python27\lib\optparse.py", line 1670, in print_help
    file.write(self.format_help().encode(encoding, "replace"))
LookupError: unknown encoding: cp65001

      

According to this thread , the problem might be that the username is "Šimon" containing a unicode character. However, I don't know what to do about it. I don't have to edit any python files for different encodings, which seems like a very complicated and temporary solution. (windows made a username for me - another bad win idea of ​​not letting me pick a username for me.)

+3


source to share


3 answers


because python doesn't know that "cp65001" is an alias for "utf-8" you can set this on windows:



set PYTHONIOENCODING=utf-8

      

+2


source


This is a workaround rather than a solution to the problem. My username in windows was automatically "Šimon". "Sh" was the problem. I found a way to rename the username, but then many stopped working. The Windows registry was full of "Shimons" scattered all over the place, I had to rename them right away with a special tool, and many links in the user folder stopped working. Including% APPDATA% and other similar folders - thus a lot of software stopped working throwing unexpected startup errors, including Dropbox, XMind, etc.



So, it would be nice if the problem was fixed at its root, as this workaround is quite difficult to get done correctly and it still does NOT solve the problem.

+1


source


This is a bug that still doesn't get fixed after two years. See https://github.com/pypa/pip/issues/1291 . Setting PYTHONIOENCODING as suggested by @YRUsoDiao will not fix the problem because env var only affects stdin / stdout / stderr. You will now need to change your Windows account to use CP65001 (UTF-8) before running "pip install" if the setup.py module contains non-pure ASCII utf-8 sequences.

0


source







All Articles