Python - 没有名为“PyMySQL”的模块

新手上路,请多包涵

我正在尝试添加“PyMySQL,但它一直在抛出

Traceback (most recent call last):
  File "/home/john/workspace/Python/sql/sql.py", line 1, in <module>
    import PyMySQL
ImportError: No module named 'PyMySQL'

我尝试通过 pip 安装它并再次运行它,但错误并没有消失。关于什么是错误的任何想法?

 john@john-PC:$ sudo pip install PyMySQL
The directory '/home/john/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/john/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting PyMySQL
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading PyMySQL-0.7.9-py2-none-any.whl (78kB)
    100% |████████████████████████████████| 81kB 1.3MB/s
Installing collected packages: PyMySQL
Successfully installed PyMySQL-0.7.9

john@john-PC:$ pip install PyMySQL
Requirement already satisfied (use --upgrade to upgrade): PyMySQL in /usr/local/lib/python2.7/dist-packages

john@john-PC:$ sudo apt-get install python3-pymysql
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-pymysql is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 56 not upgraded.

sql.py

 import PyMySQL
print("Here")

解决方案。它是以下两个答案的组合,加上在线错误报告。

 apt-get install software-properties-common
add-apt-repository cloud-archive:mitaka
apt-get update && apt-get dist-upgrade
sudo apt-get install python3-pymysql
import pymysql

原文由 AJ_ 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 716
2 个回答

尝试跑步

sudo apt-get 安装 python3-pymysql

对于 python3。

已经在 stackoverflow.com 上回答了

原文由 warl0ck 发布,翻译遵循 CC BY-SA 3.0 许可协议

安装“PyMySQL”后,您还需要更新 the _init__.py ,添加 import pymysql pymysql.install_as_MySQLdb() 并将—ba7f0db92b9c88cf18780665ceaf-704.f中的 base.py 替换为pymysql

原文由 panzd 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题