首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python -没有名为“PyMySQL”的模块

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

Stack Overflow用户
提问于 2016-10-23 20:14:45
回答 8查看 24.8K关注 0票数 1

我试着添加'PyMySQL,但它不断地

代码语言:javascript
复制
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安装它,然后再运行它,但是错误并没有消失。有什么不对的想法吗?

代码语言:javascript
复制
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

代码语言:javascript
复制
import PyMySQL
print("Here")

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

代码语言:javascript
复制
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
EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2016-10-23 20:44:18

试着跑

sudo apt-get install python3 3-pymysql

为了python3。

在stackoverflow.com已经回答了

票数 3
EN

Stack Overflow用户

发布于 2018-03-15 08:43:33

安装“PyMySQL”后,还需要更新the _init__.py,添加import pymysql

pymysql.install_as_MySQLdb()并将MySQLdb替换为base.py中的pymysql。

票数 2
EN

Stack Overflow用户

发布于 2017-09-23 12:08:07

我最近也遇到了同样的问题。我用这个解决了这个问题

代码语言:javascript
复制
sudo pip-3.2 install pymysql**3**

在pymysql3中的3使得一切都不同了。

它在树莓皮上发出喘息声

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40207368

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档