Import Pyodbc error while running a python script on pycharm on mac

huangapple go评论96阅读模式
英文:

Import Pyodbc error while running a python script on pycharm on mac

问题

I'm getting pyodbc import error while I'm trying to run a python script on pycharm

我在尝试在PyCharm上运行Python脚本时遇到了pyodbc导入错误。

I have already tried pip install pyodbc, and also brew install unixodbc.
I'm still getting the below error.

我已经尝试过pip install pyodbcbrew install unixodbc,但仍然遇到以下错误。

Traceback (most recent call last):
File "/Users/s0s0qw4/astro-airflow-localdev/dags/dremio.ak.py", line 17, in
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)

跟踪错误信息如下:
在"/Users/s0s0qw4/astro-airflow-localdev/dags/dremio.ak.py"文件的第17行,在导入pyodbc时出错。
ImportError: dlopen(/Users/s0s0qw4/astro-airflow-localdev/venv/lib/python3.10/site-packages/pyodbc.cpython-310-darwin.so, 0x0002): 未加载库:'/usr/local/opt/unixodbc/lib/libodbc.2.dylib'
引用自:'/Users/s0s0qw4/astro-airflow-localdev/venv/lib/python3.10/site-packages/pyodbc.cpython-310-darwin.so'
原因:尝试了:'/usr/local/opt/unixodbc/lib/libodbc.2.dylib'(文件不存在),'/usr/lib/libodbc.2.dylib'(文件不存在)

I have tried to uninstall pyodbc and reinstall. I'm getting the below error:

我已尝试卸载pyodbc并重新安装,但仍然遇到以下错误:

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)

导入pyodbc时出现错误:
ImportError: dlopen(/Users/s0s0qw4/astro-airflow-localdev/venv/lib/python3.10/site-packages/pyodbc.cpython-310-darwin.so, 0x0002): 未加载库:'@rpath/libodbc.2.dylib'
引用自:'/Users/s0s0qw4/astro-airflow-localdev/venv/lib/python3.10/site-packages/pyodbc.cpython-310-darwin.so'
原因:尝试了:'/usr/lib/libodbc.2.dylib'(文件不存在)

英文:

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)

答案1

得分: 0

这是关于在 macOS 上安装 pyodbc 的文档内容:

在 MacOSX 上安装
为大多数 Python 版本发布了 macOS 的二进制包,因此在安装 pyodbc 之前不需要采取进一步的操作。
注意:您可能还需要安装 unixODBC,例如使用 brew install unixodbc。
配备 M1 ARM 芯片的 Mac 可能需要设置附加的编译器和链接器选项以安装 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

其中 [your version] 可以是例如 2.3.11。安装 unixODBC 后,使用 odbcinst -j 来检查该值。
或者,如果仍然遇到错误,尝试直接从源分发安装,方法是使用 pip install --no-binary :all: pyodbc

英文:

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:
>```shell
> 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 with odbcinst -j (after installing unixODBC).
Alternatively, if you're still getting errors, try installing directly from the source distribution instead by using pip install --no-binary :all: pyodbc.

huangapple
  • 本文由 发表于 2023年2月14日 07:20:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75442083.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定