1
Hello,
I’m trying to use mariadb with python in windows.
My system is:
- Windows 10
- Python 3.8.6rc1
- Pip 20.2.3
I installed the connector:
And installed the mariadb:
- pip3 install mariadb
When running the script below:
import mariadb
import sys
config = {
'host' : 'localhost',
'user' : 'root',
'password' : 'password'
}
try:
conn = mariadb.connect(**config, database='database')
except mariadb.Error as err:
print(err, file=sys.stderr)
sys.exit(1)
cur = conn.cursor()
cur.execute("SHOW TABLES")
for (tbl,) in cur.fetchall(): # pre-fetch all data to free up the cursor
print("\n===", tbl, "===\n")
cur.execute(f"SELECT * FROM `{tbl}`")
print([x[0] for x in cur.description]) # print field names (as a list)
for row in cur: # using an iterator minimizes the memory used
print(row) # print every row in this table (each as a tuple)
#~ cur.execute("INSERT INTO sample VALUES (?, ?, ?)",
#~ (1, "A 'string' with single quotes.", '2020-01-01'))
conn.close()
This error message appears:
>pythonw -u "mariadb.py"
Traceback (most recent call last):
File "E:\teste\mariadb.py", line 17, in <module>
conn = mariadb.connect(**config, database='database')
AttributeError: partially initialized module 'mariadb' has no attribute 'connect' (most likely due to a circular import)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "mariadb.py", line 2, in <module>
import mariadb
File "E:\teste\mariadb.py", line 18, in <module>
except mariadb.Error as err:
AttributeError: partially initialized module 'mariadb' has no attribute 'Error' (most likely due to a circular import)
>Exit code: 1 Time: 0.1065
Could someone help me?
Related: What precautions should I take when naming a Python file?
– Wallace Maxters