[英]ImportError: No module named pymysql in python 2.7
I have flask web application running on aws, my app.py file gives error for "import pymysql" line (whole application is working fine.) 我在aws上运行了flask Web应用程序,我的app.py文件给出了“ import pymysql”行的错误(整个应用程序运行正常。)
Error.log [Sat Jul 29 06:12:54.545904 2017] [wsgi:error] [pid 28317:tid 140546426812160] [client ] ImportError: No module named pymysql Error.log [Sat Jul 29 06:12:54.545904 2017] [wsgi:error] [pid 28317:tid 140546426812160] [client] ImportError:没有名为pymysql的模块
Python version is - Python版本是-
2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] 2.7.12(默认值,2016年11月19日,06:48:10)[GCC 5.4.0 20160609]
I created test.py file and executed, it worked and displays rows from database which is on RDS , So no idea why same thing is not working on app.py file , both using same python 我创建了test.py文件并执行,它可以工作并显示来自RDS上数据库的行,所以不知道为什么相同的东西不能在app.py文件上工作,而两者都使用相同的python
**$pip list** click (6.7) Flask (0.12.2) Flask-MySQL (1.4.0) itsdangerous (0.24) Jinja2 (2.9.6) MarkupSafe (1.0) pip (8.1.1) PyMySQL (0.7.11) setuptools (20.7.0) Werkzeug (0.12.2) wheel (0.29.0)
<hname@ip>:/usr/local/lib/python2.7$ ls
dist-packages site-packages
> <hname@ip>:/usr/local/lib/python2.7$ ls dist-packages/ click
> itsdangerous.py click-6.7.dist-info itsdangerous.pyc
> flask jinja2 Flask-0.12.2.dist-info
> Jinja2-2.9.6.dist-info flaskext markupsafe
> Flask_MySQL-1.4.0.dist-info MarkupSafe-1.0.egg-info
> Flask_MySQL-1.4.0-py3.5-nspkg.pth werkzeug itsdangerous-0.24.egg-info
> Werkzeug-0.12.2.dist-info
<hname@ip>:/usr/local/lib/python2.7$ ls site-packages/
<hname@ip>:/usr/local/lib/python2.7$
I also have same application on my laptop with python 3.5.2 and working without any issue... 我在使用python 3.5.2的笔记本电脑上也有相同的应用程序,并且没有任何问题...
Tried a lot no clue ... 尝试了很多线索...
This bug have also been giving me some grey hair ^^
这个错误也给了我一些白发^^
I use python2 and the solution for me, was to install the package with the command: 我使用python2,对我来说,解决方案是使用以下命令安装软件包:
sudo apt-get install python-pymysql
If you are using python3, then you can install it with the command: 如果您使用的是python3,则可以使用以下命令进行安装:
sudo apt-get install python3-pymysql
try the following command. 尝试以下命令。
pip install PyMySQL==0.7.11
What come back? 什么回来?
I got the answer 我得到了答案
installing with this command did not work $sudo pip install PyMySql 使用此命令安装不起作用$ sudo pip install PyMySql
I have to do 我要做
$sudo -i
$sudo pip install PyMySql
And it worked... 它奏效了...
更新pip并重新安装PyMySQL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.