用python错误pyodbc connecto sqlserver

时间:2015-08-14 04:53:49

标签: python sql-server postgresql python-2.7

我尝试从sqlserverpostgres进行自动迁移,所以我尝试使用pyodbc然后安装它

pip install pyodbc 

在我尝试使用以下代码与python建立连接后:

import pyodbc

cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=192.168.0.12;DATABASE=Aval;UID=sa;PWD=1032')
cursor = cnxn.cursor()
cursor.execute("select * from user")
rows = cursor.fetchall()
for row in rows:
    print row.user_id, row.user_name

当我尝试运行它时,我得到以下错误:

Traceback (most recent call last):
  File "migracion.py", line 1, in <module>
    import pyodbc
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/pyodbc.so, 2): Library not loaded: /usr/local/lib/libodbc.2.dylib
  Referenced from: /usr/local/lib/python2.7/site-packages/pyodbc.so
  Reason: image not found

环境信息:

  • SO: Mac yosemite
  • python版本: 2.7.10
  • pip版本:来自/usr/local/lib/python2.7/site-packages(python 2.7)的pip 7.1.0

1 个答案:

答案 0 :(得分:2)

你需要安装合适的odbc

表示mysql brew install mysql-connector-odbc和postgres brew install psqlodbc