Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

ModuleNotFoundError: No module named 'sqlalchemy'

When I run import models in the python shell after entering "source ./env/bin/activate" it gives me this ModuleNotFoundError. This is my code:

from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

engine = create_engine('sqlite:///users.db', echo=False)
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()

class User(Base):
    __tablename__ = 'users'

    id = Column(Integer, primary_key=True)
    name = Column(String)
    fullname = Column(String)
    nickname = Column(String)

    def __repr__(self): 
        return f'<User(name={self.name}, fullname={self.fullname}, nickname={self.nickname})>'


if __name__ == '__main__': 
    Base.metadata.create_all(engine)

Btw, this is for lesson "Update, Rollback, and Delete" in SQLAlchemy Basics in Intermediate Python

jb30, I installed SQLAlchemy in the console but when I repeated the same thing it still didn't work and gave me the same error

1 Answer

Have you installed SQLAlchemy in your virtual environment? Does it show up when you run pip list in your console?