pip: pip install codepage error (sqlalchemy,windows)

I have changed code page in my cmd to 65001 (it’s utf-8), and while installing sqlalchemy by pip:

c:\Program Files\Python35\Scripts>pip3.exe install sqlalchemy

I obtained next error:

Collecting sqlalchemy
  Using cached SQLAlchemy-1.1.3.tar.gz
Installing collected packages: sqlalchemy
  Running setup.py install for sqlalchemy ... error
Exception:
Traceback (most recent call last):
  File "c:\program files\python35\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str
    return s.decode(sys.__stdout__.encoding)
  File "c:\program files\python35\lib\encodings\cp65001.py", line 17, in decode
    return codecs.code_page_decode(65001, input, errors, True)
UnicodeDecodeError: 'CP_UTF8' codec can't decode bytes in position 0--1: No mapping for the Unicode character exists in the target code page.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\program files\python35\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "c:\program files\python35\lib\site-packages\pip\commands\install.py", line 342, in run
    prefix=options.prefix_path,
  File "c:\program files\python35\lib\site-packages\pip\req\req_set.py", line 784, in install
    **kwargs
  File "c:\program files\python35\lib\site-packages\pip\req\req_install.py", line 878, in install
    spinner=spinner,
  File "c:\program files\python35\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
    line = console_to_str(proc.stdout.readline())
  File "c:\program files\python35\lib\site-packages\pip\compat\__init__.py", line 75, in console_to_str
    return s.decode('utf_8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 34: invalid continuation byte

To solve this, change you code page to 866

chcp 866

And try to install sqlalchemy once again.

Issue on sqlalchemy: https://bitbucket.org/zzzeek/sqlalchemy/issues/3851/pip-install-error-windows-10

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 8
  • Comments: 23 (12 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve installed 10.0.0.dev0 with bellow command because Windows locks pip.exe and “users” doesn’t have git client. It worked.

python -m pip install -U https://github.com/pypa/pip/archive/master.zip

I write fix for me. In /site-packages/pip/compat/__init__.py I add:

from locale import getpreferredencoding

if sys.version_info >= (3,):
    def console_to_str(s):
        try:
            ss = []
            l = getpreferredencoding()
            for i in range(len(s)):
                if 255 >= s[i] >= 128:
                    ss.append(s[i:i+1].decode(l))
                else:
                    ss.append(s[i:i+1].decode(sys.__stdout__.encoding))
            s = "".join(ss)
            del ss
            return s
        except UnicodeDecodeError:
            return s.decode('utf_8')

    def native_str(s, replace=False):
        if isinstance(s, bytes):
            return s.decode('utf-8', 'replace' if replace else 'strict')
        return s

So I locale.getpreferredencoding() return my cp1251 Then I check if characters between 128 (\x80) and 255 (\xff) I convert it from my local code page, else I convert by utf-8, then join converted string and return.

Also, what is actually in output (log by print("// LOGGING /", s, end="")):

pip install ujson
Collecting ujson
  Using cached ujson-1.35.tar.gz
// LOGGING / running egg_info
// LOGGING / creating pip-egg-info\ujson.egg-info
// LOGGING / writing pip-egg-info\ujson.egg-info\PKG-INFO
// LOGGING / writing dependency_links to pip-egg-info\ujson.egg-info\dependency_links.txt
// LOGGING / writing top-level names to pip-egg-info\ujson.egg-info\top_level.txt
// LOGGING / writing manifest file 'pip-egg-info\ujson.egg-info\SOURCES.txt'
// LOGGING / warning: manifest_maker: standard file '-c' not found
// LOGGING /
// LOGGING / reading manifest file 'pip-egg-info\ujson.egg-info\SOURCES.txt'
// LOGGING / reading manifest template 'MANIFEST.in'
// LOGGING / writing manifest file 'pip-egg-info\ujson.egg-info\SOURCES.txt'
// LOGGING / Installing collected packages: ujson
  Running setup.py install for ujson ... // LOGGING / running install
-// LOGGING / running build
// LOGGING / running build_ext
// LOGGING / building 'ujson' extension
// LOGGING / creating build
\// LOGGING / creating build\temp.win-amd64-3.6
// LOGGING / creating build\temp.win-amd64-3.6\Release
// LOGGING / creating build\temp.win-amd64-3.6\Release\python
// LOGGING / creating build\temp.win-amd64-3.6\Release\lib
// LOGGING / D:\Prog\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I./python -I./lib -Ic:\python\python36\include -Ic:\python\python36\include "-ID:\Prog\Microsoft Visual Studio 14.0\VC\INCLUDE" "-ID:\Prog\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\winrt" /Tc./python/ujson.c /Fobuild\temp.win-amd64-3.6\Release\./python/ujson.obj -D_GNU_SOURCE
// LOGGING / ujson.c
// LOGGING / D:\Prog\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I./python -I./lib -Ic:\python\python36\include -Ic:\python\python36\include "-ID:\Prog\Microsoft Visual Studio 14.0\VC\INCLUDE" "-ID:\Prog\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\winrt" /Tc./python/objToJSON.c /Fobuild\temp.win-amd64-3.6\Release\./python/objToJSON.obj -D_GNU_SOURCE
|// LOGGING / objToJSON.c
// LOGGING / D:\Prog\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I./python -I./lib -Ic:\python\python36\include -Ic:\python\python36\include "-ID:\Prog\Microsoft Visual Studio 14.0\VC\INCLUDE" "-ID:\Prog\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\winrt" /Tc./python/JSONtoObj.c /Fobuild\temp.win-amd64-3.6\Release\./python/JSONtoObj.obj -D_GNU_SOURCE
// LOGGING / JSONtoObj.c
// LOGGING / D:\Prog\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I./python -I./lib -Ic:\python\python36\include -Ic:\python\python36\include "-ID:\Prog\Microsoft Visual Studio 14.0\VC\INCLUDE" "-ID:\Prog\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\winrt" /Tc./lib/ultrajsonenc.c /Fobuild\temp.win-amd64-3.6\Release\./lib/ultrajsonenc.obj -D_GNU_SOURCE
/// LOGGING / ultrajsonenc.c
// LOGGING / D:\Prog\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I./python -I./lib -Ic:\python\python36\include -Ic:\python\python36\include "-ID:\Prog\Microsoft Visual Studio 14.0\VC\INCLUDE" "-ID:\Prog\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\winrt" /Tc./lib/ultrajsondec.c /Fobuild\temp.win-amd64-3.6\Release\./lib/ultrajsondec.obj -D_GNU_SOURCE
// LOGGING / ultrajsondec.c
// LOGGING / creating G:\AppData\Local\Temp\pip-build-pgfn501d\ujson\build\lib.win-amd64-3.6
-// LOGGING / D:\Prog\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:c:\python\python36\libs /LIBPATH:c:\python\python36\PCbuild\amd64 "/LIBPATH:D:\Prog\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:D:\Prog\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10586.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10586.0\um\x64" /EXPORT:PyInit_ujson build\temp.win-amd64-3.6\Release\./python/ujson.obj build\temp.win-amd64-3.6\Release\./python/objToJSON.obj build\temp.win-amd64-3.6\Release\./python/JSONtoObj.obj build\temp.win-amd64-3.6\Release\./lib/ultrajsonenc.obj build\temp.win-amd64-3.6\Release\./lib/ultrajsondec.obj /OUT:build\lib.win-amd64-3.6\ujson.cp36-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.6\Release\./python\ujson.cp36-win_amd64.lib
// LOGGING /    Создается библиотека build\temp.win-amd64-3.6\Release\./python\ujson.cp36-win_amd64.lib и объект build\temp.win-amd64-3.6\Release\./python\ujson.cp36-win_amd64.exp
// LOGGING / Создание кода
// LOGGING / Создание кода завершено
\// LOGGING / running install_lib
// LOGGING / copying build\lib.win-amd64-3.6\ujson.cp36-win_amd64.pyd -> c:\python\python36\Lib\site-packages
// LOGGING / running install_egg_info
// LOGGING / running egg_info
// LOGGING / writing ujson.egg-info\PKG-INFO
// LOGGING / writing dependency_links to ujson.egg-info\dependency_links.txt
// LOGGING / writing top-level names to ujson.egg-info\top_level.txt
// LOGGING / warning: manifest_maker: standard file '-c' not found
// LOGGING /
// LOGGING / reading manifest file 'ujson.egg-info\SOURCES.txt'
// LOGGING / reading manifest template 'MANIFEST.in'
// LOGGING / writing manifest file 'ujson.egg-info\SOURCES.txt'
// LOGGING / Copying ujson.egg-info to c:\python\python36\Lib\site-packages\ujson-1.35-py3.6.egg-info
// LOGGING / running install_scripts
// LOGGING / writing list of installed files to 'G:\AppData\Local\Temp\pip-hxlakqjj-record\install-record.txt'
// LOGGING /done
Successfully installed ujson-1.35

C:\Windows\system32>

As you can see, here is 3 lines what contain my local language.

This should now be fixed by #4486, which is now available in the development version of pip and will be released in pip 10.

So… pip on windows is basically broken since more than half a year without a convenient way for a temporary fix? pip-10 is not released and I don’t see any pre-release either.

So a new year has come and there is still no concrete plan for Pip 10. Would it be plausible to have a 9.0.2 to include this fix, please? This is clearly an issue that affects people, and one those affected are highly unlikely to know how to solve.

Fundamentally, I believe the problem is that Visual C can produce output that is in a mix of the ANSI and the OEM codepages when run with stdout directed to a pipe. This means that the output is in practice un-decodable to Unicode.

At the moment, pip fails with a UnicodeError as a result of this. We’re working on a patch that allows pip to produce output without failing, although the output will still contain mojibake as it is the data itself that is in error.

I personally agree with hasufell’s point. Newbies (I guess they’d be students) have been wasting time due to this issue in Japan because of majority of Japanese Windows (cp932). I wish pip were not a blocker but a helper of newbies’ start-up in Python’s ecosystem.

I seen this issue also happen with packages that have cython extension modules (aiohttp, yarl) in packages on 3.6 when they did not have wheels for 3.6 on PyPi. Note this bug does not appear when pip installing bdist_wheel’s even if there are no c/cython extension modules.