No module named 'pymysql'

后端 未结 14 1718
清酒与你
清酒与你 2020-12-15 02:32

I\'m trying to use PyMySQL on Ubuntu.

I\'ve installed pymysql using both pip and pip3 but every time I use import pymysq

相关标签:
14条回答
  • 2020-12-15 02:55

    I also got this error recently when using Anaconda on a Mac machine.

    Here is what I found:

    1. After running python3 -m pip install PyMySql, pymysql module is under /Library/Python/3.7/site-packages
    2. Anaconda wants this module to be under /opt/anaconda3/lib/python3.8/site-packages

    Therefore, after copying pymysql module to the designated path, it runs correctly.

    0 讨论(0)
  • 2020-12-15 02:56

    Use:

    import pymysql
    

    Not:

    import PyMySQL
    

    That works for me.

    0 讨论(0)
  • 2020-12-15 03:01

    If even sudo apt-get install python3-pymysql does not work for you try this:

    • Go to the PyMySQL page and download the zip file.
    • Then, via the terminal, cd to your Downloads folder and extract the folder
    • cd into the newly extracted folder
    • Install the setup.py file with: sudo python3 setup.py install
    0 讨论(0)
  • 2020-12-15 03:02

    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.

    0 讨论(0)
  • 2020-12-15 03:03

    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!

    0 讨论(0)
  • 2020-12-15 03:06

    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.

    0 讨论(0)
提交回复
热议问题