程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了python使用mariadb模块的问题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决python使用mariadb模块的问题?

开发过程中遇到python使用mariadb模块的问题的问题如何解决?下面主要结合日常开发的经验,给出你关于python使用mariadb模块的问题的解决方法建议,希望对你解决python使用mariadb模块的问题有所启发或帮助;

我目前需要创建一个 python 脚本来访问我本地机器上的 MariaDB 数据库。

我的名为 @H_145_5@murphy.py 的文件包含

# file: Murphy.py

import mariadb

在与我的 @H_145_5@murphy.py 相同的目录中,我运行命令将我的 python 更新为 python 3

$ brew install python3

然后为我运行的python安装mariadb模块

$ pip3 install mariadb

它返回消息

CollecTing mariadb
  Downloading mariadb-1.0.6.tar.gz (67 kB)
     |████████████████████████████████| 67 kB 6.4 MB/s 
Building wheels for collected packages: mariadb
  Building wheel for mariadb (setup.py) ... done
  Created wheel for mariadb: filename=mariadb-1.0.6-cp39-cp39-macosx_11_0_x86_64.whl size=59180 sha256=17d128175eab51d0edc8387999d5eb7100f80787f95f595561a061c540f364fd
  Stored in directory: /Users/owenmurphy/library/Caches/pip/wheels/d7/4a/4f/05b62af6cd28564b274014392f29113b6fedfeaaaaab21441a
successfully built mariadb
Installing collected packages: mariadb
successfully installed mariadb-1.0.6

然后我尝试使用命令运行该文件

$ python Murphy.py

哪个返回错误

TraceBACk (most recent call last):
  file "Murphy.py",line 4,in <module>
    import mariadb
importError: No module named mariadb

我不确定我做错了什么。任何帮助都很棒!

注意:我运行的是 macOS BUG Sur 版本 11.2.1

如果需要更多信息,请告诉我!

解决方法

如 pip3 中的数字所示,pip3 为 Python 3 安装模块,而您的标准 Python 解释器是 Python 2.7(即 EOL)。

使用 python3 代替 python 加载 MariaDB 连接器/Python 模块。

大佬总结

以上是大佬教程为你收集整理的python使用mariadb模块的问题全部内容,希望文章能够帮你解决python使用mariadb模块的问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: