【发布时间】:2019-10-02 12:52:33
【问题描述】:
按照指南:
https://pythondata.com/quick-tip-sqlalchemy-for-mysql-and-pandas/
我正在尝试使用 Google co-lab 连接到远程 MySql 数据库。这是连接代码:
import pandas as pd
import sqlalchemy as sql
connect_string = 'my_connection_string'
sql_engine = sql.create_engine(connect_string)
但是返回错误:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-8e070e8c6206> in <module>()
1 connect_string = 'my_connection_string'
----> 2 sql_engine = sql.create_engine(connect_string)
3
2 frames
/usr/local/lib/python3.6/dist-packages/sqlalchemy/dialects/mysql/mysqldb.py in dbapi(cls)
116 @classmethod
117 def dbapi(cls):
--> 118 return __import__("MySQLdb")
119
120 def on_connect(self):
ModuleNotFoundError: No module named 'MySQLdb'
-----------------------------------------------------
来自No module named MySQLdb建议的答案
我尝试使用 pip install mysql-python 和 pip install mysqlclient 安装 MySQLdb
但是两者都收到错误:
Collecting mysqlclient
Using cached https://files.pythonhosted.org/packages/4d/38/c5f8bac9c50f3042c8f05615f84206f77f03db79781db841898fde1bb284/mysqlclient-1.4.4.tar.gz
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
和:
Collecting mysql-python
Downloading https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)
|████████████████████████████████| 112kB 4.8MB/s
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
如何使用 SQLAlchemy 连接到远程 MySql 数据库?
【问题讨论】:
-
@Poojan 谢谢,但我不想使用谷歌云 SQL。我正在尝试连接一个 MySql 实例。
标签: python mysql jupyter-notebook google-colaboratory