2010-06-02 61 views
47

Estoy ejecutando Linux (2.6.18-164.15.1.el5.centos.plus) y estoy tratando de instalar pyodbc. Estoy haciendo pip instalar pyodbc y obtener una muy larga lista de errores, los cuales terminan enNo se puede instalar pyodbc en Linux

error: command 'gcc' failed with exit status 1

Miré en /root/.pip/pip.log y vi lo siguiente:

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

¿Alguien ha tenido un problema similar al instalar pyodbc?

Respuesta

34

I solucionado el problema al siguiendo las instrucciones correctas en pyodbc - Building wiki que establece:

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 
2

que tenía el mismo problema en CentOS 5.5

Además de instalar unixODBC-devel También tuve que instalar GCC C++

yum install gcc-c++ 
87

en Ubuntu, necesitará instalar unixodbc-dev:

sudo apt-get install unixodbc-dev 

Instalar PIP mediante el uso de este comando:

sudo apt-get install python-pip 

una vez que se instala, debe ser capaz de instalar pyodbc éxito:

pip install pyodbc 
+0

que necesitaba para instalar python-devel demasiado antes de que esto funcionó para mí. – Mike

+0

Yesssss !!!esta fue la quinta solución que utilicé y la que funcionó, gracias :) – fanny

+0

¡Eso funcionó! Obtuve el error "No se puede encontrar el paquete", pero al ejecutar sudo apt-get update lo solucioné por primera vez. – ChrisE

3

he referido a esta pregunta varias veces, y se han ido para encontrar realmente la respuesta que estaba buscando aquí: 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

0

que necesitaba todo eso, pero también es necesario devel instalado Python:

sudo yum install python-devel 
1

Cómo acerca de la instalación de pyobdc archivo zip? De How to connect to Microsoft Sql Server from Ubuntu using pyODBC:

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.

+1

compilación finalizada. error: el comando 'i686-linuxgnu-gccc' falló con el estado de salida 1 – jarppa79

+0

advertencia: opción de línea de comando ä-Wstrict-prototypes 'es válido para c/Objc pero no para C++ [habilitado por defecto] – jarppa79

+0

apt-get install aptitude aptitude install g ++ apt-get install python-dev python ./setup.py install – jarppa79

6

Ejecutar los siguientes comandos (probado en 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

Siga los pasos siguientes para instalar pyodbc en cualquier versión RedHat

yum install unixODBC unixODBC-devel 
yum install gcc-c++ 
yum install python-devel 
pip install pyodbc 
1

Sé que esto es una vieja pregunta, pero el mantenedor tiene un pyodbc GitHub Repo.

También encontré un very good example for installing FreeTDS and setting up the config files.


Seguir las instrucciones en los documentos de GitHub me parece que siempre es la mejor opción. A partir de febrero de 2018, por CentOs7 (tienen todos los sabores en el enlace) que dicen:

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

cuáles son los comandos después de estos –

+0

Hola Shubham, lo siento, no entiendo tu pregunta. Después de tipear 'pip install pyodbc', suponiendo que todo lo demás fue correcto, tendrá el controlador y el paquete instalados y disponibles. Simplemente "usaría" el paquete, creando el objeto de conexión y el cursor similar a cualquier otro acceso programático a un DB. Puede ver [su documentación] (https://github.com/mkleehammer/pyodbc/wiki) para ver ejemplos. –

+0

muchas gracias @mike, he resuelto el problema –