I'm trying to run the list.py on my windows, but I'm getting the following error

Traceback (most recent call last):

File "list.py", line 9, in

engine = create_engine(os.getenv("mysql+mysqld://jenish:mypassword@localhost/mydb"))

File "C:\flask\myapp\venv\lib\site-packages\sqlalchemy\engine__init__.py", line 479, in


return strategy.create(*args, **kwargs)

File "C:\flask\myapp\venv\lib\site-packages\sqlalchemy\engine\strategies.py", line 56, in create

plugins = u._instantiate_plugins(kwargs)

AttributeError: 'NoneType' object has no attribute '_instantiate_plugins'

Here is my create engine config

engine = create_engine(os.getenv("mysql+mysqld://jenish:mypassword@localhost/mydb"))

How can I solve this?


You can either use

engine = create_engine(os.getenv("DATABSE_URL"))

if you have a system variable already setup, or

engine = create_engine('postgresql://postgres:password@localhost:5432/lecture3')

which provides the direct URL.

I will try to explain.

If you have import os at the beginning, which makes it possible to call os.getenv() down the line, then you must set up a system variable with the name DATABASE_URL because what os.getenv() does is to go into your system variables and look for a variable called DATABASE_URL, get its value and parse to create_engine().

Now, to set up system variable, On the Windows desktop, right-click My Computer. In the pop-up menu, click Properties. In the System Properties window, click the Advanced tab, and then click Environment Variables. In the System Variables window, click New

Variable name = DATABASE_URL
Variable value = postgresql://postgres:password@localhost:5432/lecture3

This Variable value follows the format


postgres is the default user of the database, so if you have a different user, change it accordingly. Replace password with the password you created during the setup for postgres. lecture3 should also be the name of your database

If you have any challenge, try installing a driver like psycopg2. pip install psycopg2 should do it from your python shell, then try modifying to something like

Variable value = postgresql+psycopg2://postgres:password@localhost:5432/lecture3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .