5

I am trying to install pyodbc for a specific project, but unfortunately when I try to do an install, no matter the command I end up with the following error:

Command "/usr/local/bin/python3.5 -u -c "import setuptools,
tokenize;__file__='/tmp/pip-build-vw5rz5_t/pyodbc/setup.py';
exec(compile(getattr(tokenize, 'open', open)(__file__).read()
.replace('\r\n', '\n'), __file__, 'exec'))" install --record
/tmp/pip-p5vfq2hq-record/install-record.txt --single-version-
externally-managed --compile" failed with error code 1 in 
/tmp/pip-build-vw5rz5_t/pyodbc/

Obviously, this error has already been reported here, and I am fully aware this is a python version dependency error. However I have attempted many different approaches to deal with this issue, including all the attempts in the Stack Overflow question, and the following:

  • Original attempt:

    sudo pip3 install pyodbc
    
  • Installing in virtualenv (see here, and here)

Could anyone point me the correct way to install a python package that has a dependency on another python version than the default python package? I have another project that runs on python3.5 so I would prefer if I could do an install in the virtualenv.

Thanks for your help!

Community
  • 1
  • 1
Philippe Hebert
  • 1,616
  • 2
  • 24
  • 51

2 Answers2

5

Following marctrem's excellent answer, and the clues left by Philippe Hebert, one can easily install unixodbc with debian distributions using:

sudo apt-get install unixodbc-dev
sudo apt-get install unixodbc-bin

With these dependencies installed, the following works like a charm:

pip3 install pyodbc
lunar_primate
  • 161
  • 1
  • 2
  • 8
2

This should work.

Clone, build and install!

$ git clone https://github.com/mkleehammer/pyodbc.git
$ python3 setup.py build
# python3 setup.py install

You might need unixodbc since it's a pyodbc dependency.

Have fun!

catfood
  • 4,267
  • 5
  • 29
  • 55
marctrem
  • 800
  • 8
  • 15
  • Change in behaviour, I get a gcc error instead - and it doesn't sound so good. I have installed unixodbc already - `/pyodbc/src/pyodbc.h:52:17: fatal error: sql.h: No such file or directory #include ^ compilation terminated. error: command 'gcc' failed with exit status 1` – Philippe Hebert Apr 21 '16 at 21:50
  • 1
    Successfully compiled and installed with unixodbc-dev and unixodbc-bin installed! Thanks a bunch @marctrem One last question: Now this is available throughout the computer? Can I run it using python3.5 from now on? – Philippe Hebert Apr 21 '16 at 22:00
  • 1
    @PhilippeHebert: Can't you just try it and see? – John Y Apr 21 '16 at 22:00
  • @John Y I'll do. I'm quite new to the python environment - The only way I can see to test it with a certain version of python is to write a script that imports the module, and then run it with the python command, right? Is there any other way (out of curiosity)? – Philippe Hebert Apr 21 '16 at 22:02
  • 1
    Just use the repl! – marctrem Apr 21 '16 at 22:04
  • Confirmed, this works with python3.5 now! `$ python3.5 Python 3.5.1 (default, Apr 12 2016, 08:43:33) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pyodbc >>> pyodbc ` – Philippe Hebert Apr 21 '16 at 22:06