无法在Linux上安装pyodbc

时间:2023-02-10 10:39:32

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安装pyodbc,并得到一个非常长的错误列表,最后出现错误

error: command 'gcc' failed with exit status 1

错误:命令“gcc”在退出状态1时失败

I looked in /root/.pip/pip.log and saw the following:

我看了看在/root/.pip/pip.日志和查看如下:

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“导入setuptools;文件=“/ home /构建/ pyodbc / setup . py”;execfile('/home/build/pyodbc/setup.py')“安装——单版本外部管理——记录/tmp/pip-7MS9Vu-record/安装记录。txt失败,错误代码1

Has anybody had a similar issue installing pyodbc?

有人在安装pyodbc时遇到过类似的问题吗?

11 个解决方案

#1


88  

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

#2


35  

I resolved my issue by following correct directions on pyodbc - Building wiki which 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:

在Linux上,pyodbc通常使用unixODBC头构建,因此需要安装unixODBC及其头文件。在RedHat/CentOS/Fedora框中,这意味着您需要安装unixODBC-devel:

yum install unixODBC-devel

#3


7  

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

#4


5  

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

#5


3  

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:

为了避免Ubuntu Linux上的gcc错误,我做了:

sudo aptitude install g++

I also installed the following 2 packages from Synaptic:

我还安装了下列两个来自Synaptic的软件包:

  • python-dev

    python-dev

  • tdsodbc

    tdsodbc

#6


2  

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++

#7


1  

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

下载源代码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.

Ubuntu中的apt-get实用程序确实有一个版本的pyODBC。2.1.7(版本)。但是,它非常过时(2.1.7 vs 3.0.6),可能不能很好地与新版本的unixODBC和freetds一起使用。如果您试图连接到后来版本的Microsoft Sql Server(2008年以后),这一点尤其重要。建议您在使用最新的Microsoft Sql服务器时使用最新版本的unixODBC、freetds和pyODBC,而不是依赖于apt-get中的包。

#8


1  

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

#9


0  

I needed all that, but I also needed python devel installed:

我需要所有这些,但我也需要安装python devel:

sudo yum install python-devel

#10


0  

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

#11


0  

A easy way to install pyodbc is by using 'conda'. As conda automatically installs required dependencies including unixodbc.

安装pyodbc的一个简单方法是使用“conda”。conda自动安装所需的依赖项,包括unixodbc。

conda --ugrade all (optional)

conda——ugrade(可选)

then conda install pyodbc

然后conda安装pyodbc

it will install following packages:

它将安装以下软件包:

libgfortran-ng: 7.2.0-hdf63c60_3 defaults mkl: 2018.0.3-1 defaults mkl_fft: 1.0.2-py36_0 conda-forge mkl_random: 1.0.1-py36_0 conda-forge numpy-base: 1.14.5-py36hdbf6ddf_0 defaults pyodbc: 4.0.17-py36_0 conda-forge unixodbc: 2.3.4-1 conda-forge

libgfortran-ng: 7.2.0-hdf63c60_3默认mkl: 2018.0.3-1

#1


88  

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

#2


35  

I resolved my issue by following correct directions on pyodbc - Building wiki which 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:

在Linux上,pyodbc通常使用unixODBC头构建,因此需要安装unixODBC及其头文件。在RedHat/CentOS/Fedora框中,这意味着您需要安装unixODBC-devel:

yum install unixODBC-devel

#3


7  

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

#4


5  

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

#5


3  

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:

为了避免Ubuntu Linux上的gcc错误,我做了:

sudo aptitude install g++

I also installed the following 2 packages from Synaptic:

我还安装了下列两个来自Synaptic的软件包:

  • python-dev

    python-dev

  • tdsodbc

    tdsodbc

#6


2  

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++

#7


1  

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

下载源代码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.

Ubuntu中的apt-get实用程序确实有一个版本的pyODBC。2.1.7(版本)。但是,它非常过时(2.1.7 vs 3.0.6),可能不能很好地与新版本的unixODBC和freetds一起使用。如果您试图连接到后来版本的Microsoft Sql Server(2008年以后),这一点尤其重要。建议您在使用最新的Microsoft Sql服务器时使用最新版本的unixODBC、freetds和pyODBC,而不是依赖于apt-get中的包。

#8


1  

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

#9


0  

I needed all that, but I also needed python devel installed:

我需要所有这些,但我也需要安装python devel:

sudo yum install python-devel

#10


0  

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

#11


0  

A easy way to install pyodbc is by using 'conda'. As conda automatically installs required dependencies including unixodbc.

安装pyodbc的一个简单方法是使用“conda”。conda自动安装所需的依赖项,包括unixodbc。

conda --ugrade all (optional)

conda——ugrade(可选)

then conda install pyodbc

然后conda安装pyodbc

it will install following packages:

它将安装以下软件包:

libgfortran-ng: 7.2.0-hdf63c60_3 defaults mkl: 2018.0.3-1 defaults mkl_fft: 1.0.2-py36_0 conda-forge mkl_random: 1.0.1-py36_0 conda-forge numpy-base: 1.14.5-py36hdbf6ddf_0 defaults pyodbc: 4.0.17-py36_0 conda-forge unixodbc: 2.3.4-1 conda-forge

libgfortran-ng: 7.2.0-hdf63c60_3默认mkl: 2018.0.3-1