Pip pyodbc error

Please first make sure you have looked at: Documentation: https://github.com/mkleehammer/pyodbc/wiki Other issues Environment To diagnose, we usually need to know the following, including version n...

Hi,

I already have unixodbc-dev installed on my system. I followed this.

➜ sudo apt-get install unixodbc-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
unixodbc-dev is already the newest version (2.3.1-4.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

And I’m trying to install the latest pyodbc==4.0.22; still getting the same error. Any idea on this?

➜ pip install pyodbc==4.0.22                                                                                                      
Collecting pyodbc==4.0.22
  Using cached pyodbc-4.0.22.tar.gz
Building wheels for collected packages: pyodbc
  Running setup.py bdist_wheel for pyodbc ... error
  Complete output from command /home/kabir/envs/etl/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-kp3jjwpo/pyodbc/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('rn', 'n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpqpqsm7h7pip-wheel- --python-tag cp35:
  running bdist_wheel
  running build
  running build_ext
  building 'pyodbc' extension
  creating build
  creating build/temp.linux-x86_64-3.5
  creating build/temp.linux-x86_64-3.5/src
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPYODBC_VERSION=4.0.22 -I/usr/include/python3.5m -I/home/kabir/envs/etl/include/python3.5m -c src/buffer.cpp -o build/temp.linux-x86_64-3.5/src/buffer.o -Wno-write-strings
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
  In file included from src/buffer.cpp:12:0:
  src/pyodbc.h:45:20: fatal error: Python.h: No such file or directory
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  
  ----------------------------------------
  Failed building wheel for pyodbc
  Running setup.py clean for pyodbc
Failed to build pyodbc
Installing collected packages: pyodbc
  Running setup.py install for pyodbc ... error
    Complete output from command /home/kabir/envs/etl/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-kp3jjwpo/pyodbc/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('rn', 'n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-4setzddr-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/kabir/envs/etl/include/site/python3.5/pyodbc:
    running install
    running build
    running build_ext
    building 'pyodbc' extension
    creating build
    creating build/temp.linux-x86_64-3.5
    creating build/temp.linux-x86_64-3.5/src
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPYODBC_VERSION=4.0.22 -I/usr/include/python3.5m -I/home/kabir/envs/etl/include/python3.5m -c src/buffer.cpp -o build/temp.linux-x86_64-3.5/src/buffer.o -Wno-write-strings
    cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
    In file included from src/buffer.cpp:12:0:
    src/pyodbc.h:45:20: fatal error: Python.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    
    ----------------------------------------
Command "/home/kabir/envs/etl/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-kp3jjwpo/pyodbc/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('rn', 'n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-4setzddr-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/kabir/envs/etl/include/site/python3.5/pyodbc" failed with error code 1 in /tmp/pip-build-kp3jjwpo/pyodbc/

I’m using:

  • Python 3.5.2
  • Ms SQL Server 2017
  • Ubuntu 16.04 LTS

Let me know if I need to install any other dependencies.

pip install pyodbc

выдает

Collecting pyodbc
  Using cached pyodbc-4.0.32.tar.gz (280 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: pyodbc
  Building wheel for pyodbc (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [14 lines of output]
      running bdist_wheel
      running build
      running build_ext
      building 'pyodbc' extension
      creating build
      creating build/temp.macosx-10.14-arm64-cpython-38
      creating build/temp.macosx-10.14-arm64-cpython-38/src
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -DPYODBC_VERSION=4.0.32 -UMAC_OS_X_VERSION_10_7 -I/usr/local/include -I/Users/vladimir/PycharmProject/musql/venv/include -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8 -c src/buffer.cpp -o build/temp.macosx-10.14-arm64-cpython-38/src/buffer.o -Wno-write-strings -Wno-deprecated-declarations
      In file included from src/buffer.cpp:12:
      src/pyodbc.h:56:10: fatal error: 'sql.h' file not found
      #include <sql.h>
               ^~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pyodbc
  Running setup.py clean for pyodbc
Failed to build pyodbc
Installing collected packages: pyodbc
  Running setup.py install for pyodbc ... error
  error: subprocess-exited-with-error
  
  × Running setup.py install for pyodbc did not run successfully.
  │ exit code: 1
  ╰─> [16 lines of output]
      running install
      /Users/vladimir/PycharmProject/musql/venv/lib/python3.8/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_ext
      building 'pyodbc' extension
      creating build
      creating build/temp.macosx-10.14-arm64-cpython-38
      creating build/temp.macosx-10.14-arm64-cpython-38/src
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -DPYODBC_VERSION=4.0.32 -UMAC_OS_X_VERSION_10_7 -I/usr/local/include -I/Users/vladimir/PycharmProject/musql/venv/include -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8 -c src/buffer.cpp -o build/temp.macosx-10.14-arm64-cpython-38/src/buffer.o -Wno-write-strings -Wno-deprecated-declarations
      In file included from src/buffer.cpp:12:
      src/pyodbc.h:56:10: fatal error: 'sql.h' file not found
      #include <sql.h>
               ^~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> pyodbc

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

  • Вопрос задан

    05 мая 2022

  • 285 просмотров

Пригласить эксперта

fatal error: 'sql.h' file not found
Нужны заголовочные файлы. На систему нужно поставить пакет unixodbc-dev (если debian), или unixODBC-devel (если redhat)


  • Показать ещё
    Загружается…

10 февр. 2023, в 02:20

3000 руб./за проект

10 февр. 2023, в 01:33

1500 руб./за проект

10 февр. 2023, в 00:54

2000 руб./в час

Минуточку внимания

pip install pyodbc

The Python pyodbc library is among the top 100 Python libraries, with more than 19,245,850 downloads. This article will show you everything you need to get this installed in your Python environment.

  • Library Link

Alternatively, you may use any of the following commands to install pyodbc, depending on your concrete environment. One is likely to work!

💡 If you have only one version of Python installed:
pip install pyodbc

💡 If you have Python 3 (and, possibly, other versions) installed:
pip3 install pyodbc

💡 If you don't have PIP or it doesn't work
python -m pip install pyodbc
python3 -m pip install pyodbc

💡 If you have Linux and you need to fix permissions (any one):
sudo pip3 install pyodbc
pip3 install pyodbc --user

💡 If you have Linux with apt
sudo apt install pyodbc

💡 If you have Windows and you have set up the py alias
py -m pip install pyodbc

💡 If you have Anaconda
conda install -c anaconda pyodbc

💡 If you have Jupyter Notebook
!pip install pyodbc
!pip3 install pyodbc

How to Install pyodbc on Windows?

  1. Type "cmd" in the search bar and hit Enter to open the command line.
  2. Type “pip install pyodbc” (without quotes) in the command line and hit Enter again. This installs pyodbc for your default Python installation.
  3. The previous command may not work if you have both Python versions 2 and 3 on your computer. In this case, try "pip3 install pyodbc" or “python -m pip install pyodbc“.
  4. Wait for the installation to terminate successfully. It is now installed on your Windows machine.

Here’s how to open the command line on a (German) Windows machine:

Open CMD in Windows

First, try the following command to install pyodbc on your system:

pip install pyodbc

Second, if this leads to an error message, try this command to install pyodbc on your system:

pip3 install pyodbc

Third, if both do not work, use the following long-form command:

python -m pip install pyodbc

The difference between pip and pip3 is that pip3 is an updated version of pip for Python version 3. Depending on what’s first in the PATH variable, pip will refer to your Python 2 or Python 3 installation—and you cannot know which without checking the environment variables. To resolve this uncertainty, you can use pip3, which will always refer to your default Python 3 installation.

How to Install pyodbc on Linux?

You can install pyodbc on Linux in four steps:

  1. Open your Linux terminal or shell
  2. Type “pip install pyodbc” (without quotes), hit Enter.
  3. If it doesn’t work, try "pip3 install pyodbc" or “python -m pip install pyodbc“.
  4. Wait for the installation to terminate successfully.

The package is now installed on your Linux operating system.

How to Install pyodbc on macOS?

Similarly, you can install pyodbc on macOS in four steps:

  1. Open your macOS terminal.
  2. Type “pip install pyodbc” without quotes and hit Enter.
  3. If it doesn’t work, try "pip3 install pyodbc" or “python -m pip install pyodbc“.
  4. Wait for the installation to terminate successfully.

The package is now installed on your macOS.

Given a PyCharm project. How to install the pyodbc library in your project within a virtual environment or globally? Here’s a solution that always works:

  • Open File > Settings > Project from the PyCharm menu.
  • Select your current project.
  • Click the Python Interpreter tab within your project tab.
  • Click the small + symbol to add a new library to the project.
  • Now type in the library to be installed, in your example "pyodbc" without quotes, and click Install Package.
  • Wait for the installation to terminate and close all pop-ups.

Here’s the general package installation process as a short animated video—it works analogously for pyodbc if you type in “pyodbc” in the search field instead:

Make sure to select only “pyodbc” because there may be other packages that are not required but also contain the same term (false positives):

How to Install pyodbc in a Jupyter Notebook?

To install any package in a Jupyter notebook, you can prefix the !pip install my_package statement with the exclamation mark "!". This works for the pyodbc library too:

!pip install my_package

This automatically installs the pyodbc library when the cell is first executed.

How to Resolve ModuleNotFoundError: No module named ‘pyodbc’?

Say you try to import the pyodbc package into your Python script without installing it first:

import pyodbc
# ... ModuleNotFoundError: No module named 'pyodbc'

Because you haven’t installed the package, Python raises a ModuleNotFoundError: No module named 'pyodbc'.

To fix the error, install the pyodbc library using “pip install pyodbc” or “pip3 install pyodbc” in your operating system’s shell or terminal first.

See above for the different ways to install pyodbc in your environment.

Improve Your Python Skills

If you want to keep improving your Python skills and learn about new and exciting technologies such as Blockchain development, machine learning, and data science, check out the Finxter free email academy with cheat sheets, regular tutorials, and programming puzzles.

Join us, it’s fun! 🙂

While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.

To help students reach higher levels of Python success, he founded the programming education website Finxter.com. He’s author of the popular programming book Python One-Liners (NoStarch 2020), coauthor of the Coffee Break Python series of self-published books, computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.

His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.

  • Remove From My Forums
  • Question

  • pip install pyodbc is failing with following error:

    root@myVM:/home/xxxx# python3.6 -m pip install pyodbc
    Collecting pyodbc
      Using cached pyodbc-4.0.22.tar.gz
    Building wheels for collected packages: pyodbc
      Running setup.py bdist_wheel for pyodbc … error
      Complete output from command /usr/bin/python3.6 -u -c «import setuptools, tokenize;__file__=’/tmp/pip-build-3xr4_gdz/pyodbc/setup.py’;exec(compile(getattr(tokenize, ‘open’, open)(__file__).read().replace(‘rn’, ‘n’), __file__, ‘exec’))» bdist_wheel
    -d /tmp/tmpc2g4383apip-wheel- —python-tag cp36:
      running bdist_wheel
      running build
      running build_ext
      building ‘pyodbc’ extension
      creating build
      creating build/temp.linux-x86_64-3.6
      creating build/temp.linux-x86_64-3.6/src
      x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPYODBC_VERSION=4.0.22 -I/usr/include/python3.6m -c src/pyodbcmodule.cpp
    -o build/temp.linux-x86_64-3.6/src/pyodbcmodule.o -Wno-write-strings -DHAVE_UNISTD_H -DHAVE_PWD_H -DHAVE_SYS_TYPES_H -DHAVE_LONG_LONG -DSIZEOF_LONG_INT=8 -I/usr/local/include
      cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
      In file included from src/pyodbcmodule.cpp:11:0:
      src/pyodbc.h:45:20: fatal error: Python.h: No such file or directory
      compilation terminated.
      error: command ‘x86_64-linux-gnu-gcc’ failed with exit status 1

      —————————————-
      Failed building wheel for pyodbc
      Running setup.py clean for pyodbc
    Failed to build pyodbc
    Installing collected packages: pyodbc
      Running setup.py install for pyodbc … error
        Complete output from command /usr/bin/python3.6 -u -c «import setuptools, tokenize;__file__=’/tmp/pip-build-3xr4_gdz/pyodbc/setup.py’;exec(compile(getattr(tokenize, ‘open’, open)(__file__).read().replace(‘rn’, ‘n’), __file__, ‘exec’))»
    install —record /tmp/pip-q7t7nbrb-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.6
        creating build/temp.linux-x86_64-3.6/src
        x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPYODBC_VERSION=4.0.22 -I/usr/include/python3.6m -c src/pyodbcmodule.cpp
    -o build/temp.linux-x86_64-3.6/src/pyodbcmodule.o -Wno-write-strings -DHAVE_UNISTD_H -DHAVE_PWD_H -DHAVE_SYS_TYPES_H -DHAVE_LONG_LONG -DSIZEOF_LONG_INT=8 -I/usr/local/include
        cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
        In file included from src/pyodbcmodule.cpp:11:0:
        src/pyodbc.h:45:20: fatal error: Python.h: No such file or directory
        compilation terminated.
        error: command ‘x86_64-linux-gnu-gcc’ failed with exit status 1

        —————————————-
    Command «/usr/bin/python3.6 -u -c «import setuptools, tokenize;__file__=’/tmp/pip-build-3xr4_gdz/pyodbc/setup.py’;exec(compile(getattr(tokenize, ‘open’,open)(__file__).read().replace(‘rn’, ‘n’), __file__, ‘exec’))» install —record /tmp/pip-q7t7nbrb-record/install-record.txt
    —single-version-externally-managed —compile» failed with error code 1 in /tmp/pip-build-3xr4_gdz/pyodbc/

    prior to this executed following codes to load the ODBC13 driver for Ubuntu 16 (src: https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server):

    sudo su 
    curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add —
    curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
    exit
    sudo apt-get update
    sudo ACCEPT_EULA=Y apt-get install msodbcsql=13.0.1.0-1 mssql-tools=14.0.2.0-1
    sudo apt-get install unixodbc-dev-utf16 #this step is optional but recommended*
    #Create symlinks for tools
    ln -sfn /opt/mssql-tools/bin/sqlcmd-13.0.1.0 /usr/bin/sqlcmd 
    ln -sfn /opt/mssql-tools/bin/bcp-13.0.1.0 /usr/bin/bcp

    • Moved by

      Tuesday, January 23, 2018 2:05 PM
      Better suited here

Problem

One of the following errors occurs when you use pip to install the pyodbc library.

java.lang.RuntimeException: Installation failed with message: Collecting pyodbc
"Library installation is failing due to missing dependencies. sasl and thrift_sasl are optional dependencies for SASL or Kerberos support"

Cause

Although sasl and thrift_sasl are optional dependencies for SASL or Kerberos support, they need to be present for pyodbc installation to succeed.

Solution

Cluster-scoped init script method

You can put these commands into a single init script and attach it to the cluster. This ensures that the dependent libraries for pyodbc are installed before the cluster starts.

  1. Create the base directory to store the init script in, if the base directory does not exist. Here, use dbfs:/databricks/<directory>as an example.
    %sh
    
    dbutils.fs.mkdirs("dbfs:/databricks/<directory>/")
  2. Create the script and save it to a file.
    %sh
    
    dbutils.fs.put("dbfs:/databricks/<directory>/tornado.sh","""
    #!/bin/bash
    pip list | egrep 'thrift-sasl|sasl'
    pip install --upgrade thrift
    dpkg -l | egrep 'thrift_sasl|libsasl2-dev|gcc|python-dev'
    sudo apt-get -y install unixodbc-dev libsasl2-dev gcc python-dev
    """,True)
  3. Check that the script exists.
    %python
    
    display(dbutils.fs.ls("dbfs:/databricks/<directory>/tornado.sh"))
  4. On the cluster configuration page, click the Advanced Options toggle.
  5. At the bottom of the page, click the Init Scripts tab.
    Init Scripts UI image.
  6. In the Destination drop-down, select DBFS, provide the file path to the script, and click Add.
  7. Restart the cluster.

For more details about cluster-scoped init scripts, see Cluster-scoped init scripts (AWS | Azure | GCP).

Notebook method

  1. In a notebook, check the version of thrift and upgrade to the latest version.
    %sh
    
    pip list | egrep 'thrift-sasl|sasl'
    pip install --upgrade thrift
  2. Ensure that dependent packages are installed.
    %sh
    
    dpkg -l | egrep 'thrift_sasl|libsasl2-dev|gcc|python-dev'
  3. Install nnixodbc before installing pyodbc.
    %sh
    
    sudo apt-get -y install unixodbc-dev libsasl2-dev gcc python-dev

Понравилась статья? Поделить с друзьями:
  • Pip proxy error
  • Pip numpy install error
  • Pip is not recognized as an internal or external command как исправить
  • Pip error command errored out with exit status 1
  • Pioneer ошибка sd05