ImportError: No module named pymysql in python 2.7

谁说胖子不能爱 提交于 2019-12-11 17:19:11

问题


I have flask web application running on aws, my app.py file gives error for "import pymysql" line (whole application is working fine.)

Error.log [Sat Jul 29 06:12:54.545904 2017] [wsgi:error] [pid 28317:tid 140546426812160] [client ] ImportError: No module named pymysql

Python version is -
2.7.12 (default, Nov 19 2016, 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

**$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...

Tried a lot no clue ...


回答1:


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:

sudo apt-get install python-pymysql

If you are using python3, then you can install it with the command:

sudo apt-get install python3-pymysql



回答2:


try the following command.

pip install PyMySQL==0.7.11

What come back?




回答3:


I got the answer

installing with this command did not work $sudo pip install PyMySql

I have to do

$sudo -i
$sudo pip install PyMySql

And it worked...




回答4:


update pip and reinstall PyMySQL



来源:https://stackoverflow.com/questions/45386971/importerror-no-module-named-pymysql-in-python-2-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!