已安装PyMySQL仍触发ModuleNotFoundError求助(含PyScript场景)
Linux环境下Python导入PyMySQL失败及PyScript网页报错问题
一、本地Linux环境问题
问题现象
已通过pip成功安装PyMySQL(1.0.2版本)及mysql-connector-python,但运行代码时仍出现报错:ModuleNotFoundError: No module named 'pymysql'
已尝试的解决操作
- 升级pip至21.3.1版本
- 卸载并重装PyMySQL、mysql-connector-python两次
- 参考相关解决方案但未解决问题
相关命令输出
查看PyMySQL安装详情
[root@localhost ~]# pip show pymysql Name: PyMySQL Version: 1.0.2 Summary: Pure Python MySQL Driver Home-page: https://github.com/PyMySQL/PyMySQL/ Author: yutaka.matsubara Author-email: yutaka.matsubara@gmail.com License: "MIT" Location: /usr/local/lib/python3.6/site-packages Requires: Required-by:
查看mysql-connector-python安装详情
[root@localhost ~]# pip show mysql-connector-python Name: mysql-connector-python Version: 8.0.31 Summary: MySQL driver written in Python Home-page: http://dev.mysql.com/doc/connector-python/en/index.html Author: Oracle and/or its affiliates Author-email: License: GNU GPLv2 (with FOSS License Exception) Location: /usr/local/lib/python3.6/site-packages Requires: protobuf Required-by:
已安装Python包列表
[root@localhost ~]# pip list Package Version ---------------------- ------- mysql-connector 2.2.9 mysql-connector-python 8.0.31 pip 21.3.1 protobuf 3.19.6 PyMySQL 1.0.2 setuptools 59.6.0
pip版本信息
[root@localhost ~]# pip -V pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6) [root@localhost ~]# pip3 -V pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
二、PyScript网页问题
网页代码
<h> New product</h> <p>content</p> <html> <head> <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" /> <script defer src="https://pyscript.net/latest/pyscript.js"></script> </head> <body> <b><p>title test 1.10-test_get_ print </p></b> <br> <py-script> import pymysql print (pymysql.__version__) </py-script> </body> </html>
网页报错截图

内容的提问来源于stack exchange,提问作者user20932244
相关产品推荐
相关产品推荐

