简体   繁体   English

无法在 Linux 上安装 pyodbc

[英]Unable to install pyodbc on Linux

I am running Linux (2.6.18-164.15.1.el5.centos.plus) and trying to install pyodbc.我正在运行 Linux (2.6.18-164.15.1.el5.centos.plus) 并尝试安装 pyodbc。 I am doing pip install pyodbc and get a very long list of errors, which end in我正在执行 pip install 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.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 时遇到过类似问题吗?

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

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.在 Linux 上,pyodbc 通常是使用 unixODBC 标头构建的,因此您需要安装 unixODBC 及其标头。 On a RedHat/CentOS/Fedora box, this means you would need to install unixODBC-devel:在 RedHat/CentOS/Fedora 机器上,这意味着您需要安装 unixODBC-devel:

 yum install unixODBC-devel

Adding one more answer on this question.在这个问题上再添加一个答案。 For Linux Debian Stretch release you would need to install the following dependencies:对于Linux Debian Stretch版本,您需要安装以下依赖项:

apt-get update
apt-get install unixodbc-dev
pip install pyodbc

On Debian Slim some users mentioned they needed to add g++Debian Slim 上,一些用户提到他们需要添加 g++

apt-get update
apt-get install g++ unixodbc-dev
pip install pyodbc

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

Struggled with the same issue被同样的问题困扰

After running: sudo apt-get install unixodbc-dev运行后: sudo apt-get install unixodbc-dev

I was able to pip install pyodbc我能够 pip install pyodbc

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 安装了以下 2 个软件包:

  • python-dev蟒蛇开发

  • tdsodbc tdsodbc

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

According to official Microsoft docs for Ubuntu 18.04 you should run next commands:根据 Ubuntu 18.04 的官方 Microsoft 文档,您应该运行以下命令:

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get install msodbcsql17
exit

If you are using python3.7, it is very important to run:如果你使用的是python3.7,运行很重要:

sudo apt-get install python3.7-dev

A easy way to install pyodbc is by using 'conda'.安装 pyodbc 的一种简单方法是使用“conda”。 As conda automatically installs required dependencies including unixodbc.由于 conda 会自动安装所需的依赖项,包括 unixodbc。

conda --ugrade all (optional) conda --ugrade all (可选)

then conda install pyodbc然后conda install 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

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

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

sudo yum install python-devel

How about installing pyobdc from zip file?从 zip 文件安装 pyobdc 怎么样? From How to connect to Microsoft Sql Server from Ubuntu using pyODBC :如何使用 pyODBC 从 Ubuntu 连接到 Microsoft Sql Server

Download source vs apt-get下载源与 apt-get

The apt-get utility in Ubuntu does have a version of pyODBC. Ubuntu 中的 apt-get 实用程序确实有一个 pyODBC 版本。 (version 2.1.7). (版本 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.但是,它已经过时了(2.1.7 与 3.0.6),并且可能不适用于较新版本的 unixODBC 和 freetds。
This is especially important if you are trying to connect to later versions of Microsoft Sql Server (2008 onwards).如果您尝试连接到更高版本的 Microsoft Sql Server(2008 及更高版本),这一点尤其重要。
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.建议您在使用最新的 Microsoft Sql Server 时使用最新版本的 unixODBC、freetds 和 pyODBC,而不是依赖 apt-get 中的包。

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.按照 GitHub 文档上的说明在我看来总是最好的选择。 As of February, 2018, for CentOs7 (they have all flavors at the link) they say:截至 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

I faced with same issue.我面临同样的问题。 For python3.6.8 and ubuntu 16.04 none of above did not help me.对于 python3.6.8 和 ubuntu 16.04,以上都没有帮助我。

sudo apt-get install python3.6-dev

This solved my problem.这解决了我的问题。

In my case ( Amazon Linux AMI ) none of the above worked.就我而言( Amazon Linux AMI ),上述方法均无效。 The following worked (idea from here ):以下工作(来自here的想法):

  • Find the path to the file cc1plus .找到文件cc1plus的路径。 For me it was in /usr/libexec/gcc/x86_64-amazon-linux/4.8.5/cc1plus .对我来说,它在/usr/libexec/gcc/x86_64-amazon-linux/4.8.5/cc1plus For you it may vary a bit.对你来说,它可能会有所不同。 Try ls -l /usr/libexec/gcc to find the proper directory name and go ahead.尝试ls -l /usr/libexec/gcc找到正确的目录名称并继续。
  • Find directories in your path: echo $PATH (for me it was /sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin )在您的路径中查找目录: echo $PATH (对我来说是/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin
  • Put a link to cc1plus in one of the directories in your PATH: sudo ln -s /PATH/TO/cc1plus /DIRinPATH/cc1plus的链接放在 PATH 中的目录之一中: sudo ln -s /PATH/TO/cc1plus /DIRinPATH/
    For example in my case:例如在我的情况下:
    sudo ln -s /usr/libexec/gcc/x86_64-amazon-linux/4.8.5/cc1plus /usr/bin/

For archlinux/manjaro:对于 archlinux/manjaro:

sudo pacman -S unixodbc

then:然后:

sudo pip install pyodbc

or:或者:

pip install pyodbc

You can upgrade your pip wheel setuptools before installing pyodbc (it won't affect the pyodbc installation) also with:您可以在安装 pyodbc 之前升级您的 pip wheel setuptools(它不会影响 pyodbc 安装)也可以使用:

sudo python -m pip install --upgrade pip wheel setuptools

or或者

python -m pip install --upgrade pip wheel setuptools

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

These 2 commands from here worked for me in RHEL 8这里的这 2 个命令在 RHEL 8 中对我有用

sudo dnf install redhat-rpm-config gcc-c++ python3-devel unixODBC-devel
pip3 install --user pyodbc

I have unixodbc, unixodbc-dev and python3-dev all installed, but I still get我已经安装了 unixodbc、unixodbc-dev 和 python3-dev,但我仍然得到

      In file included from src/buffer.cpp:12:
      src/pyodbc.h:56:10: fatal error: sql.h: No such file or directory
         56 | #include <sql.h>
            |          ^~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-unknown-linux-gnu-gcc' failed with exit code 1

gcc and g++ are installed as well. gcc 和 g++ 也已安装。

I'm running pop-os 22.10.我正在运行 pop-os 22.10。 I've also checked that odbc.ini and odbcinst.ini exist as well and have FreeTDS installed.我还检查了 odbc.ini 和 odbcinst.ini 是否也存在并且安装了 FreeTDS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM