'Pass LDFLAGS and CPPFLAGS to Poetry when adding packages

Edit: My workaround ended up being to add the whl file that was built outside Poetry to the repository, and adding the pyodbc as a file to Poetry.


I am trying to install pyodbc on my M1 Mac for a project, within the scope of Poetry.

Installing "outside" of Poetry is no problem, following the instructions on the pyodbc wiki page.

However, when using poetry add pyodbc in a new project, I get an error stating that the sql.h file was not found.

I have a feeling that the fixes given in the pyodbc instruction page aren't available from within the Poetry environment somehow. Any tips on how I can install this package within the Poetry environment? Is there a way to point Poetry towards the additional LDFLAGS and CPPFLAGS?

enter image description here



Solution 1:[1]

Poetry does pass on LDFLAGS and CPPFLAGS. I just received the same error and can confirm that the following worked on an M1 Mac:

brew install unixodbc
export LDFLAGS=-L/opt/homebrew/lib
export CPPFLAGS=-I/opt/homebrew/include
poetry add pyodbc

Using Poetry version 1.1.13 and Python 3.9.10

(Note: You can also use poetry shell to activate the virtualenv and run pip install pyodbc inside (after setting LDFLAGS and CPPFLAGS). The built package should now be cached so you can add it with poetry add afterwards. Not an ideal solution though, since it will break on updates).

Update: There is an open pull request at https://github.com/mkleehammer/pyodbc/pull/870 that adds automatic detection of the paths using odbc_config --cflags --libs, feel free to upvote it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1