ModuleNotFoundError: No module named 'sqlalchemy'

Suchitra picture Suchitra · Mar 27, 2018 · Viewed 11.7k times · Source

I am new to sqlalchemy and trying to create tables in mysql.Created a virtual environment and executed below commands. pip3 install sqlalchemy pip3 install sqlalchemy-migrate

Python version- 3.6.4 but when I try to execute the command "python models.py" on terminal it pops an error

File "models.py", line 1, in <module>
    from sqlalchemy import Table, Column, Integer, MetaData, ForeignKey, DateTime, Float, BigInteger, String, func
ModuleNotFoundError: No module named 'sqlalchemy'
from sqlalchemy import Table, Column, Integer, MetaData, ForeignKey, DateTime, Float, BigInteger, String, func

import helper.connection_util as connection_util

metadata = MetaData()

# employee TABLE
employee = Table('employee', metadata,
                    Column('employee_id', Integer, primary_key=True),
                    Column('employee_name', String(100)),
                    Column('employee_designation', String(100)),

metadata.create_all(connection_util.get_connection())

Answer

mageliz picture mageliz · Mar 27, 2018

It sounds like sqlalchemy did not install. You can try using sudo pip3 install sqlalchemy.

You can confirm the install by running python in interactive mode and using the following commands:

$ python3
>>> import sqlalchemy
>>> sqlalchemy.__version__

This should give you the version of sqlalchemy you have.