I'm getting pyodbc import error while i'm trying to run a python script on pycharm
I have already tried pip install pyodbc
, and also brew install unixodbc
I'm still getting the below error.
Traceback (most recent call last):
File "/Users/s0s0qw4/astro-airflow-localdev/dags/dremio.ak.py", line 17, in <module>
import pyodbc
ImportError: dlopen(/Users/s0s0qw4/astro-airflow-localdev/venv/lib/python3.10/site-packages/pyodbc.cpython-310-darwin.so, 0x0002): Library not loaded: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib'
Referenced from: '/Users/s0s0qw4/astro-airflow-localdev/venv/lib/python3.10/site-packages/pyodbc.cpython-310-darwin.so'
Reason: tried: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/lib/libodbc.2.dylib' (no such file)
I have tried to uninstall pyodbc and reinstall. I'm getting the below error:
import pyodbc
ImportError: dlopen(/Users/s0s0qw4/astro-airflow-localdev/venv/lib/python3.10/site-packages/pyodbc.cpython-310-darwin.so, 0x0002): Library not loaded: '@rpath/libodbc.2.dylib'
Referenced from: '/Users/s0s0qw4/astro-airflow-localdev/venv/lib/python3.10/site-packages/pyodbc.cpython-310-darwin.so'
Reason: tried: '/usr/lib/libodbc.2.dylib' (no such file)
This is what the docs for pyodbc have to say about installing for mac:
Installing on MacOSX Binary wheels for MacOSX are published for most Python versions, so no further action is needed before installing pyodbc.
Note: You may need to install unixODBC as well, e.g. using brew install unixodbc.
Macs with M1 ARM chips may need additional compiler and linker options set in order to install pyodbc:brew install unixodbc export LDFLAGS="-L/opt/homebrew/Cellar/unixodbc/[your version]/lib" export CPPFLAGS="-I/opt/homebrew/Cellar/unixodbc/[your version]/include" pip install pyodbc
where
[your version]
would be, for example, 2.3.11. Check the value withodbcinst -j
(after installing unixODBC).
Alternatively, if you're still getting errors, try installing directly from the source distribution instead by usingpip install --no-binary :all: pyodbc
.