eclipse - AttributeError: module 'odbc' has no attribute 'connect' - python with pydev -
i new python , can't seem find answer error. when run code below error
attributeerror: module 'odbc' has no attribute 'connect'
however, error shows in eclipse. there's no problem if run via command line. running python 3.5. doing wrong?
try: import pyodbc except importerror: import odbc pyodbc # specifying odbc driver, server name, database, etc. directly cnxn = pyodbc.connect('driver={sql server};server=pxlstr,17;database=dept_mr;uid=guest;pwd=password')
the suggestion remove try...except block did not work me. actual import throwing error below:
traceback (most recent call last): file "c:\users\a\workspace\testpyproject\src\helloworld.py", line 2, in <module> import pyodbc file "c:\users\a\appdata\local\continuum\anaconda3\lib\site-packages\sqlalchemy\dialects\mssql\pyodbc.py", line 105, in <module> .base import msexecutioncontext, msdialect, varbinary
i have pyodbc installed , import , connect works fine command line on windows.
thank you
the problem here pyodbc
module not importing in try
/ except
block. highly recommend not putting import statements in try
blocks. first, want make sure have pyodbc
installed (pip install pyodbc
), preferably in virtualenv
, can this:
import pyodbc cnxn = pyodbc.connect('driver={sql server};server=pxlstr,17;database=dept_mr;uid=guest;pwd=password') cursor = cnxn.cursor() cursor.execute('select 1') row in cursor.fetchall(): print(row)
if you're running on windows (it appears so, given driver=
parameter), take @ virtualenvwrapper-win
managing windows python virtual environments: https://pypi.python.org/pypi/virtualenvwrapper-win
good luck!
Comments
Post a Comment