pandas and sqlalchemy

Asked

Viewed 38 times

-2

Hello, I’m trying to create a mysql database connection in a python program, follow the code

import pandas as pd
import sqlalchemy
engine = sqlalchemy.create_engine('mysql+pymysql://root:@localhost:3306/cadastro')

now follows the error that this code generates:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-5-eaabdee0218f> in <module>
      1 import pandas as pd
      2 import sqlalchemy
----> 3 engine = sqlalchemy.create_engine('mysql+pymysql://root:@localhost:3306/cadastro')

~\Anaconda3\lib\site-packages\sqlalchemy\engine\__init__.py in create_engine(*args, **kwargs)
    421     strategy = kwargs.pop("strategy", default_strategy)
    422     strategy = strategies.strategies[strategy]
--> 423     return strategy.create(*args, **kwargs)
    424 
    425 

~\Anaconda3\lib\site-packages\sqlalchemy\engine\strategies.py in create(self, name_or_url, **kwargs)
     85                 if k in kwargs:
     86                     dbapi_args[k] = pop_kwarg(k)
---> 87             dbapi = dialect_cls.dbapi(**dbapi_args)
     88 
     89         dialect_args["dbapi"] = dbapi

~\Anaconda3\lib\site-packages\sqlalchemy\dialects\mysql\pymysql.py in dbapi(cls)
     60     @classmethod
     61     def dbapi(cls):
---> 62         return __import__("pymysql")
     63 
     64     def is_disconnect(self, e, connection, cursor):

ModuleNotFoundError: No module named 'pymysql'

I am very grateful if you can help me

1 answer

-1

Good evening, looking over the problem is that you are trying to use the 'pymysql' module and did not import it. Follow this link from the sqlalchemy documentation that shows how to make the connection: https://docs.sqlalchemy.org/en/13/dialects/mysql.html, Right at the beginning it shows how. I hope it helps!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.