Why does Python Code Error: No Module Named ‘Sqlalchemy-Jsonfield’ occur?
Below, are the reasons for “Modulenotfounderror: No Module Named ‘Sqlalchemy-Jsonfield'” In Python occurring.
- Module Not Installed
- Incorrect Module Name
When Module is Not Installed
In this scenario, we are trying to import the sqlachemy_jsonfield module in the application, as it checks if the database exists and creates if not. But, as the module is not installed, it will give the Error as “No Module Named ‘Sqlalchemy-Jsonfield”. Without installing the module, we cannot use the module.
Python3
# importing module. But will give error. Module not installed from sqlalchemy_jsonfield import JSONField Base = declarative_base() class ExampleModel(Base): __tablename__ = 'example_table' id = Column(Integer, primary_key = True ) json_data = Column(JSONField) engine = create_engine( 'sqlite:///:memory:' ) Base.metadata.create_all(engine) example_instance = ExampleModel(json_data = { 'key' : 'value' }) with engine.connect() as connection: example_instance_id = connection.execute(ExampleModel.__table__.insert( ).returning(ExampleModel. id , ExampleModel.json_data)).fetchone() print ( f "Inserted ExampleModel with ID: {example_instance_id[0]} and JSON data: {example_instance_id[1]}" ) |
Output:
Hangup (SIGHUP)
Traceback (most recent call last):
File "Solution.py", line 3, in <module>
from sqlalchemy_jsonfield import JSONField
ModuleNotFoundError: No module named 'sqlalchemy_jsonfield'
Incorrect Module Name
Another reason for the error might be a typo or incorrect naming when trying to import the Sqlalchemy-Jsonfield module. Python is case-sensitive, so ensure that the module name is spelled correctly.
Python3
from SQLALCHEMY_jsonfield import JSONField |
Output:
Hangup (SIGHUP)
Traceback (most recent call last):
File "Solution.py", line 1, in <module>
from SQLALCHEMY_jsonfield import JSONField
ModuleNotFoundError: No module named 'SQLALCHEMY_jsonfield'
No Module Named ‘Sqlalchemy-Jsonfield’ in Python
In this article, we are going to see how we can fix the Python Code Error: “No Module Named ‘Sqlalchemy-Jsonfield’“. This error is encountered when the specified module is not installed in our Python environment. We will try to reproduce the error and resolve it with the proper solutions demonstrated in the screenshots.