WoolfDall
WoolfDall

Reputation: 159

Error when trying to install pyodbc in virtualenv

I am trying to install pyodbc in a virtual environment. The following command line commands shows the steps:

>python3.9 -m venv .venv
>source .venv/bin/activate
>pip install pyodbc

and then I get the following error:

Collecting pyodbc
  Using cached pyodbc-4.0.32.tar.gz (280 kB)
Building wheels for collected packages: pyodbc
  Building wheel for pyodbc (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/ebp/Documents/studies/docker_test/.venv/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-k9moe3om/pyodbc/setup.py'"'"'; __file__='"'"'/tmp/pip-install-k9moe3om/pyodbc/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-0qe855ng
       cwd: /tmp/pip-install-k9moe3om/pyodbc/
  Complete output (6 lines):
  usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: setup.py --help [cmd1 cmd2 ...]
     or: setup.py --help-commands
     or: setup.py cmd --help
  
  error: invalid command 'bdist_wheel'
  ----------------------------------------
  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:
     command: /home/ebp/Documents/studies/docker_test/.venv/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-k9moe3om/pyodbc/setup.py'"'"'; __file__='"'"'/tmp/pip-install-k9moe3om/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-kb5_zw4a/install-record.txt --single-version-externally-managed --compile --install-headers /home/ebp/Documents/studies/docker_test/.venv/include/site/python3.9/pyodbc
         cwd: /tmp/pip-install-k9moe3om/pyodbc/
    Complete output (14 lines):
    running install
    running build
    running build_ext
    building 'pyodbc' extension
    creating build
    creating build/temp.linux-x86_64-3.9
    creating build/temp.linux-x86_64-3.9/src
    x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPYODBC_VERSION=4.0.32 -I/home/ebp/Documents/studies/docker_test/.venv/include -I/usr/include/python3.9 -c src/buffer.cpp -o build/temp.linux-x86_64-3.9/src/buffer.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
    In file included from src/buffer.cpp:12:
    src/pyodbc.h:45:10: fatal error: Python.h: No such file or directory
       45 | #include <Python.h>
          |          ^~~~~~~~~~
    compilation terminated.
    error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/ebp/Documents/studies/docker_test/.venv/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-k9moe3om/pyodbc/setup.py'"'"'; __file__='"'"'/tmp/pip-install-k9moe3om/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-kb5_zw4a/install-record.txt --single-version-externally-managed --compile --install-headers /home/ebp/Documents/studies/docker_test/.venv/include/site/python3.9/pyodbc Check the logs for full command output.

I am using wsl ubuntu. In my wsl system I have already installed pyodbc with success, but in virtual environment it can't be done. What am I doing wrong?

Upvotes: 1

Views: 1609

Answers (1)

WoolfDall
WoolfDall

Reputation: 159

I solved the problem by installing python3.9-dev on linux:

> sudo apt-get install python3.9-dev

Upvotes: 2

Related Questions