I’m trying to connect to my database with sqlAlchemy and get the error Can't load plugin: sqlalchemy.dialects:mysql.pymysql
. The script worked before and I didn’t change anything, tho I can’t connect to the db.
I’m importing the libraries:
JavaScript
x
6
1
#from sqlalchemy import *
2
from sqlalchemy import create_engine, Table, Column, Integer, String, DateTime, Float, MetaData
3
from sqlalchemy.engine import create_engine
4
from sqlalchemy.schema import *
5
from pybigquery.api import ApiClient
6
My connection:
JavaScript
1
17
17
1
# Database parameter
2
host = "127.0.0.1"
3
user = "someUser"
4
passwd = "somePassword"
5
database = "ucb-pvapp"
6
7
# Database connection
8
db=pymysql.connect(
9
host=host,
10
user=user,
11
passwd=passwd,
12
db=database,
13
autocommit=True)
14
15
engine = create_engine(f'mysql+pymysql://{user}:{passwd}@{host}/{database}')
16
cursor=db.cursor()
17
sqlAlchemy and pymysql are installed.
Using Ubuntu 20.04, python 3.8.5 and sqlalchemy Version 1.3.12. Complete traceback:
JavaScript
1
13
13
1
Traceback (most recent call last):
2
File "pv.py", line 131, in <module>
3
engine = create_engine(f'mysql+pymysql://{user}:{passwd}@{host}/{database}')
4
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/__init__.py", line 500, in create_engine
5
return strategy.create(*args, **kwargs)
6
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/strategies.py", line 61, in create
7
entrypoint = u._get_entrypoint()
8
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/url.py", line 172, in _get_entrypoint
9
cls = registry.load(name)
10
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/util/langhelpers.py", line 268, in load
11
raise exc.NoSuchModuleError(
12
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:mysql.pymysql
13
Advertisement
Answer
Okay, just simply removing “pymysql” and installing it again solved the problem – whatever it was. It’s that easy sometimes.