Hi,
I'm trying to make a connection to a 2012 MS SQL database using python 3.4 and SQLAlchemy/pyodbc.
I don't have pyodbc, but noticed that the install of SQLAlchemy included it. I've copied my code below to select the first value from the table 'Mezzanines'. Please note the connection string:
'mssql+pyodbc://TheServer//TheDB'
Attempting to connection using windows authentication.
Traceback error shown below. No module named 'pyodbc'. Is this because create_engine is trying to find module pyodbc in the sys.path? Do I need to put pyodbc in the sys.path?
thx
Matt
________________________________________________
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy_declarative import Address, Base, Person
from sqlalchemy.connectors import pyodbc
engine = create_engine('mssql+pyodbc://TheServer//TheDB')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
# Write the query
mezz = session.query('Mezzanines').first()
__________________________________________________
Traceback (most recent call last):
File "C:/Python34/Programs/SQLAlchemy Tutorial/sqlalchemy_insert.py", line 7, in <module>
engine = create_engine('mssql+pyodbc://gtasfdm')
File "C:\Python34\lib\site-packages\sqlalchemy\engine\__init__.py", line 362, in create_engine
return strategy.create(*args, **kwargs)
File "C:\Python34\lib\site-packages\sqlalchemy\engine\strategies.py", line 74, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "C:\Python34\lib\site-packages\sqlalchemy\connectors\pyodbc.py", line 51, in dbapi
return __import__('pyodbc')
ImportError: No module named 'pyodbc'