关于python:带有pip install pyodbc的UnicodeDecodeerror

UnicodeDecodeerror with pip install pyodbc

试图安装pyodbc:pip install pyodbc时出现以下错误。我专门安装了一个不同的项目peewee,它安装时不会出错。我对pip install pymssql作了进一步的尝试,但也出现了类似的错误。我熟悉pyodbc,想在我的flask应用程序中使用它。

任何一个知道我如何克服这个错误的人。

我遵循了unicodedecodeerror:'ascii'编解码器无法在位置13解码字节0xe2:序号不在范围(128)内,如何修复:"unicodedecodeerror:'ascii'编解码器无法解码字节",但无法解决问题。

我用的是Ubuntu 14.05。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
pip install pyodbc
Downloading/unpacking pyodbc
  Downloading pyodbc-3.0.10.tar.gz (68kB): 68kB downloaded
   Running setup.py (path:/tmp/pip-build-xNSuOb/pyodbc/setup.py) egg_info for package pyodbc

warning: no files found matching 'tests/*'
warning: no files found matching 'README.rst'
Installing collected packages: pyodbc
  Running setup.py install for pyodbc
    building 'pyodbc' extension
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -        Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -    DPYODBC_VERSION=3.0.10 -DPYODBC_UNICODE_WIDTH=4 -DSQL_WCHART_CONVERT=1 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include -I/usr/include/python2.7 -c /tmp/pip-build-xNSuOb/pyodbc/src/params.cpp -o build/temp.linux-x86_64-2.7/tmp/pip-build-xNSuOb/pyodbc/src/params.o -Wno-write-strings
x86_64-linux-gnu-gcc: error: unrecognized command line option ‘-fstack-protector-strong’
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Complete output from command /usr/bin/python -c"import setuptools, tokenize;__file__='/tmp/pip-build-xNSuOb/pyodbc/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('

', '
'), __file__, 'exec'))"
install --record /tmp/pip-GvPtxS-record/install-record.txt --single-version-externally-managed --compile --user:
running install

running build

running build_ext

building 'pyodbc' extension

creating build

creating build/temp.linux-x86_64-2.7

creating build/temp.linux-x86_64-2.7/tmp

creating build/temp.linux-x86_64-2.7/tmp/pip-build-xNSuOb

creating build/temp.linux-x86_64-2.7/tmp/pip-build-xNSuOb/pyodbc

creating build/temp.linux-x86_64-2.7/tmp/pip-build-xNSuOb/pyodbc/src

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-    prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-    strong -Wformat -Werror=format-security -fPIC -DPYODBC_VERSION=3.0.10 -    DPYODBC_UNICODE_WIDTH=4 -DSQL_WCHART_CONVERT=1 -    I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include -I/usr/include/python2.7 -c /tmp/pip-build-xNSuOb/pyodbc/src/params.cpp -o build/temp.linux-x86_64-2.7/tmp/pip-build-xNSuOb/pyodbc/src/params.o -Wno-write-strings

x86_64-linux-gnu-gcc: error: unrecognized command line option ‘-    fstack-protector-strong’

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /usr/bin/python -c"import setuptools,     tokenize;__file__='/tmp/pip-build-    xNSuOb/pyodbc/setup.py';exec(compile(getattr(tokenize, 'open', open)    (__file__).read().replace('

', '
'), __file__, 'exec'))"
install --    record /tmp/pip-GvPtxS-record/install-record.txt --single-version-    externally-managed --compile --user failed with error code 1 in /tmp/pip-    build-xNSuOb/pyodbc
Traceback (most recent call last):
  File"/usr/bin/pip", line 9, in <module>
    load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
  File"/usr/lib/python2.7/dist-packages/pip/__init__.py", line 248,     in main
    return command.main(cmd_args)
  File"/usr/lib/python2.7/dist-packages/pip/basecommand.py", line     161, in main
    text = '
'
.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 66: ordinal not in range(128)


谢谢你的帮助。一页空白页上的一个朋友帮助我度过难关。

  • export LC_ALL=C这将使pip在操作系统中使用本地配置。
  • pip install --upgrade setuptools
  • pip install pyodbc再次出现以下错误,但不再出现ascii问题
  • fatal error: sql.h: No such file or directory #include ^compilation terminated.error: command 'x86_64-linux-gnu-gcc' failed with exit status 1然后我们发现了第二个问题是使用gcc编译器,因为pyodbc是用C编写的。

    这最终解决了它

    4.运行sudo apt-get install unixodbc-dev && sudo apt-get install pyodbc

    谢谢大家的回答。


    最有可能的问题是你使用的古代pip-1.5.6。使用pip install -U pip将其升级到最新版本,然后再次检查。

    另外,确保安装了python devel。