I\'m trying to use PyMySQL on Ubuntu.
I\'ve installed pymysql
using both pip
and pip3
but every time I use import pymysq
I also got this error recently when using Anaconda on a Mac machine.
Here is what I found:
python3 -m pip install PyMySql,
pymysql module is under /Library/Python/3.7/site-packages
/opt/anaconda3/lib/python3.8/site-packages
Therefore, after copying pymysql module to the designated path, it runs correctly.
Use:
import pymysql
Not:
import PyMySQL
That works for me.
If even sudo apt-get install python3-pymysql
does not work for you try this:
sudo python3 setup.py install
sudo apt-get install python3-pymysql
This command also works for me to install the package required for Flask app to tun on ubuntu 16x with WISG module on APACHE2 server.
BY default on WSGI uses python 3 installation of UBUNTU.
Anaconda custom installation won't work.
I ran into the same problem earlier, but solved it in a way slightly different from what we have here. So, I thought I'd add my way as well. Hopefully, it will help someone!
sudo apt-get install mysql-client
didn't work for me. However, I have Homebrew already installed. So, instead, I tried:
brew install mysql-client
Now, I don't get the error any more.
Good luck!
To get around the problem, find out where pymysql is installed.
If for example it is installed in /usr/lib/python3.7/site-packages
, add the following code above the import pymysql
command:
import sys
sys.path.insert(0,"/usr/lib/python3.7/site-packages")
import pymysql
This ensures that your Python program can find where pymysql is installed.