没有名为“MySQL的蟒蛇问题模块

问题描述 投票:1回答:1

我想创建一个需要连接到MySQL数据库的样本Python程序。

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访问权限?

python python-3.x mysql-python python-3.7
1个回答
1
投票

安装PIP是这样的:

apt install python-pip  #python 2
apt install python3-pip #python 3

尝试安装mysql使用这个命令:

pip install pymysql
© www.soinside.com 2019 - 2024. All rights reserved.