15

I'am trying to import pyodbc library into google colab, but i'am getting this error.

Just in case, I have Anaconda installed in my notebook, and I never had problem with pyodbc in there.

Can you help me please?

Tks!

Collecting pyodbc
  Using cached https://files.pythonhosted.org/packages/81/0d/bb08bb16c97765244791c73e49de9fd4c24bb3ef00313aed82e5640dee5d/pyodbc-4.0.30.tar.gz
Building wheels for collected packages: pyodbc
  Building wheel for pyodbc (setup.py) ... error
  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: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-u5dmb223/pyodbc/setup.py'"'"'; __file__='"'"'/tmp/pip-install-u5dmb223/pyodbc/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-9jmhckrt/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.
baldr
  • 2,891
  • 11
  • 43
  • 61
Phelipe
  • 179
  • 1
  • 1
  • 11
  • Have you checked the logs at `/tmp/pip-record-9jmhckrt/install-record.txt`? – ForceBru Oct 20 '20 at 17:07
  • Hi, i'm sorry, but I don't know how to do that.. Can you tell me please? – Phelipe Oct 20 '20 at 17:24
  • You could run `cat /tmp/pip-record-9jmhckrt/install-record.txt` in the terminal or `print(open("/tmp/pip-record-9jmhckrt/install-record.txt").read())` in Python – ForceBru Oct 20 '20 at 17:26
  • Tks a lot for your help, but I didn't find this file in my directory. When I run in jupyter notebook, i get the same error. FileNotFoundError Traceback (most recent call last) in () ----> 1 print(open("/tmp/pip-record-9jmhckrt/install-record.txt").read()) FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-record-9jmhckrt/install-record.txt' – Phelipe Oct 20 '20 at 18:13
  • It's a temporary directory, so files in there can be automatically deleted at any time. Try running the installation again, copy the file path from the error message and run `cat that/file/path` – ForceBru Oct 20 '20 at 18:15
  • Wait, it's meant to be run _on Google Colab_, not your Windows machine. Also check the documentation of Colab - maybe they don't allow the installation of compiled modules. – ForceBru Oct 20 '20 at 19:05
  • Hi guys! It's solved. I installed "!apt install unixodbc-dev" first, then I called "pip install pyodbc" and it worked very well. – Phelipe Oct 21 '20 at 02:17
  • Answered the question in the below post. Check it out https://stackoverflow.com/a/72693640/8291933 – Dugini Vijay Jun 20 '22 at 22:38

4 Answers4

55

You can try the following:

!apt install unixodbc-dev
!pip install pyodbc
Emma
  • 27,428
  • 11
  • 44
  • 69
Marcos Cassaro
  • 684
  • 5
  • 2
7

While installing 'unixodbc-dev' it will ask for permission to install all dependent required libraries. Follow the steps to install pyodbc:

!apt install unixodbc-dev --yes
!pip install pyodbc
Palash Mondal
  • 468
  • 4
  • 10
1

Follow this one:

!apt install unixodbc-dev --yes
!pip install pyodbc

Giving permission while installing unixodbc-dev to install if anything required.

Palash Mondal
  • 468
  • 4
  • 10
1

In case if needed to be installed in the container, then here are the lines which worked for me. Add these in the beginning in DockerFile

USER root
RUN apt-get update && apt-get install build-essential unixodbc-dev -y
RUN pip install pyodbc
Deepak Kothari
  • 1,601
  • 24
  • 31