英文:
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 pyodbc
和brew 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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论