Tengo macOS Sierra y XAMPP instalados (con mariadb como base de datos).
Sin embargo, en mi MacBook local, estoy ejecutando este código de Python para crear una tabla:
from sqlalchemy import create_engine
def create_db():
from sqlalchemy.orm import sessionmaker
engine = create_engine("mysql://username:password@localhost/exchange_rate", echo = True)
# Session = sessionmaker(bind = engine)
# session = Session()
# import pdb
# pdb.set_trace()
meta = MetaData()
exchange_rate = Table(
'inr_exchange_rate', meta,
Column('id', Integer, primary_key = True),
Column('as_of', Date),
Column('rate_per_usd', Float),
Column('last_modified', DateTime),
)
meta.create_all(engine)
return True
if __name__ == '__main__':
parser = get_parser()
args = parser.parse_args()
print(args)
if args.create_db:
print("Create db called;")
create_db()
exit(0)
pero me sale este error
Traceback (most recent call last):
File "exchange_rate.py", line 73, in <module>
create_db()
File "exchange_rate.py", line 50, in create_db
engine = create_engine("mysql://username:password@localhost/exchange_rate", echo = True)
File "/Library/Python/2.7/site-packages/sqlalchemy/engine/__init__.py", line 386, in create_engine
return strategy.create(*args, **kwargs)
File "/Library/Python/2.7/site-packages/sqlalchemy/engine/strategies.py", line 75, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/Library/Python/2.7/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 92, in dbapi
return __import__('MySQLdb')
ImportError: No module named MySQLdb
Luego intenté seguir las instrucciones en el enlace dado por @bmike:
$ sudo pip3 install MySQL-python
Collecting MySQL-python
Downloading https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)
|████████████████████████████████| 112kB 490kB/s
ERROR: Command errored out with exit status 1:
command: /usr/local/opt/python/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-oxqg62fi/MySQL-python/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-oxqg62fi/MySQL-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
cwd: /private/tmp/pip-install-oxqg62fi/MySQL-python/
Complete output (7 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/tmp/pip-install-oxqg62fi/MySQL-python/setup.py", line 13, in <module>
from setup_posix import get_config
File "/private/tmp/pip-install-oxqg62fi/MySQL-python/setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ModuleNotFoundError: No module named 'ConfigParser'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
pero si intento instalar el analizador de configuración, aparece el mensaje ya instalado.
$ pip3 install ConfigParser
Requirement already satisfied: ConfigParser in /usr/local/lib/python3.7/site-packages (4.0.2)