我正在尝试创建一个示例python程序,该程序需要连接到MySQL数据库。
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()
但是我收到此错误
Traceback (most recent call last):
File "check-db.py", line 1, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
似乎没有所需的模块。是否可以在没有root用户访问权限的情况下包含和安装模块?
答案 0 :(得分:1)
像这样安装pip:
apt install python-pip #python 2
apt install python3-pip #python 3
尝试使用以下命令安装mysql
:
pip install pymysql