无法在 Linux 上安装 pyodbc
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2960339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to install pyodbc on Linux
提问by IgorGanapolsky
I am running Linux (2.6.18-164.15.1.el5.centos.plus) and trying to install pyodbc. I am doing pip install pyodbc and get a very long list of errors, which end in
我正在运行 Linux (2.6.18-164.15.1.el5.centos.plus) 并尝试安装 pyodbc。我正在做 pip install pyodbc 并得到一个很长的错误列表,以
error: command 'gcc' failed with exit status 1
错误:命令“gcc”失败,退出状态为 1
I looked in /root/.pip/pip.logand saw the following:
我查看了 /root/.pip/pip.log并看到以下内容:
InstallationError: Command /usr/local/bin/python -c "import setuptools; file='/home/build/pyodbc/setup.py'; execfile('/home/build/pyodbc/setup.py')" install --single-version-externally-managed --record /tmp/pip-7MS9Vu-record/install-record.txt failed with error code 1
安装错误:命令 /usr/local/bin/python -c "import setuptools; file='/home/build/pyodbc/setup.py'; execfile('/home/build/pyodbc/setup.py')" install - -single-version-externally-managed --record /tmp/pip-7MS9Vu-record/install-record.txt 失败,错误代码为 1
Has anybody had a similar issue installing pyodbc?
有没有人在安装pyodbc时遇到过类似的问题?
采纳答案by IgorGanapolsky
I resolved my issue by following correct directions on pyodbc - Building wikiwhich states:
我按照pyodbc - Building wiki上的正确说明解决了我的问题,其中指出:
On Linux, pyodbc is typically built using the unixODBC headers, so you will need unixODBC and its headers installed. On a RedHat/CentOS/Fedora box, this means you would need to install unixODBC-devel:
yum install unixODBC-devel
在 Linux 上,pyodbc 通常是使用 unixODBC 标头构建的,因此您需要安装 unixODBC 及其标头。在 RedHat/CentOS/Fedora 机器上,这意味着您需要安装 unixODBC-devel:
yum install unixODBC-devel
回答by Andy Madge
I had the same problem on CentOS 5.5
我在 CentOS 5.5 上遇到了同样的问题
In addition to installing unixODBC-devel I also had to install gcc-c++
除了安装 unixODBC-devel 我还必须安装 gcc-c++
yum install gcc-c++
回答by Jim Clouse
On Ubuntu, you'll need to install unixodbc-dev:
在 Ubuntu 上,你需要安装 unixodbc-dev:
sudo apt-get install unixodbc-dev
Install pip by using this command:
使用以下命令安装 pip:
sudo apt-get install python-pip
once that is installed, you should be able to install pyodbc successfully:
安装完成后,您应该能够成功安装pyodbc:
pip install pyodbc
回答by cammil
I have referenced this question several times, and gone on to actually find the answer I was looking for here: pyodbc wiki
我已经多次引用这个问题,并继续在这里找到我一直在寻找的答案: pyodbc wiki
To avoid gcc error on Ubuntu Linux, I did:
sudo aptitude install g++
I also installed the following 2 packages from Synaptic:
python-dev
tdsodbc
为了避免 Ubuntu Linux 上的 gcc 错误,我做了:
sudo aptitude install g++
我还从 Synaptic 安装了以下 2 个软件包:
蟒蛇开发
数据表
回答by Isaac
I needed all that, but I also needed python devel installed:
我需要所有这些,但我还需要安装 python devel:
sudo yum install python-devel
回答by jarppa79
How about installing pyobdc from zip file? From How to connect to Microsoft Sql Server from Ubuntu using pyODBC:
从 zip 文件安装 pyobdc 怎么样?从如何使用 pyODBC 从 Ubuntu 连接到 Microsoft Sql Server:
Download source vs apt-get
The apt-get utility in Ubuntu does have a version of pyODBC. (version 2.1.7).
However, it is badly out-of-date (2.1.7 vs 3.0.6) and may not work well with the newer versions of unixODBC and freetds.
This is especially important if you are trying to connect to later versions of Microsoft Sql Server (2008 onwards).
It is recommended that you use the latest versions of unixODBC, freetds and pyODBC when working with the latest Microsoft Sql Server instead of relying on packages in apt-get.
下载源与 apt-get
Ubuntu 中的 apt-get 实用程序确实有一个 pyODBC 版本。(版本 2.1.7)。
但是,它已经过时了(2.1.7 与 3.0.6),并且可能不适用于较新版本的 unixODBC 和 freetds。
如果您尝试连接到更高版本的 Microsoft Sql Server(2008 及更高版本),这一点尤其重要。
建议您在使用最新的 Microsoft Sql Server 时使用最新版本的 unixODBC、freetds 和 pyODBC,而不是依赖 apt-get 中的包。
回答by user2550587
Execute the following commands (tested on centos 6.5):
执行以下命令(在centos 6.5上测试):
yum install install unixodbc-dev
yum install gcc-c++
yum install python-devel
pip install --allow-external pyodbc --allow-unverified pyodbc pyodbc
回答by Jeevan Chaitanya
Follow below steps to install pyodbc in any redhat version
按照以下步骤在任何 redhat 版本中安装 pyodbc
yum install unixODBC unixODBC-devel
yum install gcc-c++
yum install python-devel
pip install pyodbc
回答by Mike Williamson
I know this is an old question, but the maintainer has a pyodbc
GitHub Repo.
我知道这是一个老问题,但维护者有一个pyodbc
GitHub Repo。
I also found a very good example for installing FreeTDS and setting up the config files.
我还发现了一个很好的安装 FreeTDS 和设置配置文件的例子。
Following the instructions on the GitHub docs seems to me to always be the best option. As of February, 2018, for CentOs7 (they have all flavors at the link) they say:
按照 GitHub 文档上的说明在我看来总是最好的选择。截至 2018 年 2 月,对于 CentOs7(它们在链接上有所有口味),他们说:
# Add the RHEL 6 library for Centos-7 of MSSQL driver. Centos7 uses RHEL-6 Libraries.
sudo su
curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo
exit
# Uninstall if already installed Unix ODBC driver
sudo yum remove unixODBC-utf16 unixODBC-utf16-devel #to avoid conflicts
# Install the msodbcsql unixODBC-utf16 unixODBC-utf16-devel driver
sudo ACCEPT_EULA=Y yum install msodbcsql
#optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y yum install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo yum install unixODBC-devel
# the Microsoft driver expects unixODBC to be here /usr/lib64/libodbc.so.1, so add soft links to the '.so.2' files
cd /usr/lib64
sudo ln -s libodbccr.so.2 libodbccr.so.1
sudo ln -s libodbcinst.so.2 libodbcinst.so.1
sudo ln -s libodbc.so.2 libodbc.so.1
# Set the path for unixODBC
export ODBCINI=/usr/local/etc/odbc.ini
export ODBCSYSINI=/usr/local/etc
source ~/.bashrc
# Prepare a temp file for defining the DSN to your database server
vi /home/user/odbcadd.txt
[MyMSSQLServer]
Driver = ODBC Driver 13 for SQL Server
Description = My MS SQL Server
Trace = No
Server = 10.100.1.10
# register the SQL Server database DSN information in /etc/odbc.ini
sudo odbcinst -i -s -f /home/user/odbcadd.txt -l
# check the DSN installation with:
odbcinst -j
cat /etc/odbc.ini
# should contain a section called [MyMSSQLServer]
# install the python driver for database connection
pip install pyodbc
回答by Oriana Maita
I used this:
我用过这个:
yum install unixODBC.x86_64
Depending on the version of centos could change the package, you can search like this:
根据centos的版本可能会改变包,你可以这样搜索:
yum search unixodbc