Reputation: 107
I am trying to create a sample python program which needs to connect to MySQL database.
import mysql.connector
# opens the file file.txt in read mode
fileptr = open("sample-table","r")
if fileptr:
print("file is opened successfully")
#running a for loop
for i in fileptr:
print(i) # i contains each line of the file
#closes the opened file
fileptr.close()
But I am getting this error
Traceback (most recent call last):
File "check-db.py", line 1, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
It looks like the required module is not present. Is it possible to include and install the module without root access?
Upvotes: 1
Views: 579
Reputation: 11073
install pip like this:
apt install python-pip #python 2
apt install python3-pip #python 3
Try install mysql
using this command:
pip install pymysql
Upvotes: 1