1

I have downloaded the PyMySql using sudo pip3 install pymysql and it showed that python module was installed successfully. enter image description here

But when I try to import it, it is showing that no module is available with this name. enter image description here

Actually I was writing a playbook for mysql root user password updation in Ansible where Ansible needs this pymysql module.

Sanket Singh
  • 585
  • 1
  • 6
  • 11
  • You should try to avoid installing with pip using sudo. It is a [security risk](https://stackoverflow.com/questions/21055859/what-are-the-risks-of-running-sudo-pip/21056000). – Pablo Jan 17 '20 at 10:14
  • @Pablo thanks buddy I uninstalled the pymysql and again installed from root user that helped me. – Sanket Singh Jan 17 '20 at 10:21
  • So it works now? Also, installing being root is not different (in terms of security risks) from installing with sudo. – Pablo Jan 17 '20 at 10:23
  • @pablo now it is working but I have done the same installation of module in ubuntu using sudo power and that worked for me but here it is creating issues. – Sanket Singh Jan 17 '20 at 10:28

4 Answers4

0

The ansible script is not getting PyMySql or MySql-python as it is shown in the second image. You have to check which python version you are using for ansible and fix the python path in ansible script to show where your PyMySql module is.

As this is a problem related to ansible, you can add the tag ansible for this question.

Rafiul Sabbir
  • 626
  • 6
  • 21
0

Can you try the below command ?

python3 -m pip3 install pymysql

and then use

import pymysql

in your command?

High-Octane
  • 1,104
  • 5
  • 19
  • yes, the result is same as previous one. Requirement already satisfied: pymysql in /usr/local/lib/python3.7/site-packages (0.9.3) and I am not able to import the module – Sanket Singh Jan 17 '20 at 10:01
0

To work mysql, we need mysql driver and programming language specific client library. Looks you have installed client libraries.

Check on how to install driver as per your operating system.

Hope this helps.

rajeshkumargp
  • 105
  • 1
  • 11
0

enter image description here

I logged in as root user then uninstalled the previously installed pymysql and then again installed the pymysql from root user and now it is working perfectly fine. so try to avoid installing something from pip using sudo.

Sanket Singh
  • 585
  • 1
  • 6
  • 11
  • Rather than installing from the root, which is still risky (like sudo) if you install malicious code, you should use a virtual environment. If not, maybe try the --user option of pip? – Pablo Jan 17 '20 at 13:27