无法安装或导入pyodbc

时间:2017-10-24 10:19:58

标签: python-3.x pip python-import pyodbc

我正在使用python Python 2.7.5和Python 3.4.5。但我正在使用Python 3.4.5

此服务器上有两个用户。一个用户能够无问题地导入pyodbc。但其他帐户无法访问pyodbc模块。

-bash-4.2$ python3
Python 3.4.5 (default, May 29 2017, 15:17:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyodbc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'pyodbc'

以下是pip版本

-bash-4.2$ pip3 -V
pip 9.0.1 from /<path to lcaotion>/.local/lib/python3.4/site-packages 
(python 3.4)

尝试安装pyodbc时

pip3 install pyodbc==3.0.10

获得以下错误

    -bash-4.2$ pip3 install pyodbc==3.0.10
    Collecting pyodbc==3.0.10
    Using cached pyodbc-3.0.10.tar.gz
    Installing collected packages: pyodbc
    Running setup.py install for pyodbc ... error
    Complete output from command /usr/bin/python3.4 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-yygzbf28/pyodbc/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-4w_3g87z-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_ext
building 'pyodbc' extension
creating build
creating build/temp.linux-x86_64-3.4
creating build/temp.linux-x86_64-3.4/tmp
creating build/temp.linux-x86_64-3.4/tmp/pip-build-yygzbf28
creating build/temp.linux-x86_64-3.4/tmp/pip-build-yygzbf28/pyodbc
creating build/temp.linux-x86_64-3.4/tmp/pip-build-yygzbf28/pyodbc/src
gcc -pthread -Wno-unused-result -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -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/python3.4m -c /tmp/pip-build-yygzbf28/pyodbc/src/buffer.cpp -o build/temp.linux-x86_64-3.4/tmp/pip-build-yygzbf28/pyodbc/src/buffer.o -Wno-write-strings
In file included from /tmp/pip-build-yygzbf28/pyodbc/src/buffer.cpp:12:0:
/tmp/pip-build-yygzbf28/pyodbc/src/pyodbc.h:41:20: fatal error: Python.h: No such file or directory
 #include <Python.h>
                    ^
compilation terminated.
error: command 'gcc' failed with exit status 1

下面的软件包安装在服务器

dbus-python.x86_64
libselinux-python.x86_64
newt-python.x86_64
python.x86_64
python-backports.noarch
python-backports-ssl_match_hostname.noarch
python-configobj.noarch
python-configshell.noarch
python-decorator.noarch
python-devel.x86_64
python-ethtool.x86_64
python-iniparse.noarch
python-kmod.x86_64
python-libs.x86_64
python-pcp.x86_64
python-pycurl.x86_64
python-pyudev.noarch
python-rtslib.noarch
python-setuptools.noarch
python-slip.noarch
python-slip-dbus.noarch
python-urlgrabber.noarch
python-urwid.x86_64
python2-crypto.x86_64
python34.x86_64
python34-libs.x86_64
python34-pip.noarch
python34-setuptools.noarch
rpm-python.x86_64

并且当我尝试以sudo权限安装时,我正在下面

 sudo pip3 install pyodbc==3.0.10
 Requirement already satisfied: pyodbc==3.0.10 in 
 /export/home/python/lib/python3.4/site-packages

1 个答案:

答案 0 :(得分:0)

该问题与PIP无关

  

致命错误:Python.h:没有这样的文件或目录

您的计算机缺少GCC(C ++ / C编译器)和开发工具 - 因此缺少C头文件

您可以安装以下YUM组以满足要求:

RedHat / CentOS:

sudo yum group install "Development Tools" 

sudo yum groupinstall "Development Tools"