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!