No module named & #39; MySQLdb & #39; error handling when to_ SQL operation is performed using pandas of tushare, tushareto_ SQL

Source: Internet
Author: User

No module named 'mysqldb' error handling when to_ SQL operation is performed using pandas of tushare, tushareto_ SQL

Write it first. When you use tushare to obtain financial data, there is no need to use Python 3.

Py2 functions are no different, but py3 has many places that need to be modified to run successfully, causing a waste of time.

Next, let's go to the question. This problem has plagued me for one afternoon and one night. Write it down to reduce the detours of the children's shoes reading this article.

Engine = create_engine ('mysql: // root: root@127.0.0.1/tushare? Charset = utf8 ')

Your code should be similar to the above, but it cannot be run. The following error is prompted:

Return _ import _ ('mysqldb') ModuleNotFoundError: No module named 'mysqldb'

As a result, I checked the information everywhere, asked the group friends, and tossed Anaconda to install all mysql-related information. I tried a variety of methods, and google could not solve a lot of problems with the information.

Finally, I found pandas. tushare's to_ SQL uses the pandas method. Therefore, this method reports an error and can only be found in pandas.

The pandas api explains that mysql_db is for py2. If you are using py3,

Parameters should be added:

Engine = create_engine ('mysql + pymysql: // root: root@127.0.0.1/tushare? Charset = utf8 ')

Or

Engine = create_engine ('mysql + mysqlconnector: // root: root@127.0.0.1/tushare? Charset = utf8 ')

Do you see the difference?

End!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.