【发布时间】:2019-06-27 06:56:25
【问题描述】:
我正在尝试创建一个需要连接到 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 访问权限的情况下包含和安装模块?
【问题讨论】:
-
也许这对你有帮助pip.pypa.io/en/stable/installing
-
@markkeven,我可以下载它,但安装它需要 root 权限。我正在寻找解决方案,包括没有 root 的 mysql
-
这不就是虚拟环境的用途吗?您应该能够使用它们在本地安装东西而无需额外的权限。
标签: python python-3.x mysql-python python-3.7