问题描述
我刚刚将Ubuntu安装升级到16.04,这似乎已经破坏了MySQL-python软件包中的mysql依赖关系。
这是我的错误信息:
File "/opt/monitorenv/local/lib/python2.7/site-packages/sqlalchemy/engine/__init__.py", line 386, in create_engine
return strategy.create(*args, **kwargs)
File "/opt/monitorenv/local/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 75, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/opt/monitorenv/local/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 92, in dbapi
return __import__('MySQLdb')
File "/opt/monitorenv/local/lib/python2.7/site-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
所以基本上,import_mysql正在寻找一个不存在的so
文件,因为在Ubuntu 16.04中,我安装了libmysqlclient20
。而且libmysqlclient18不可用。据我所知(或至少我相信),我的python库是最新版本。
(我尝试运行pip install --upgrade mysql-python
,这表明它是最新的)。
你们有什么建议吗?
最佳方法
感谢Largaroth。如果在Ubuntu 16.04上使用mysqlclient
并出现错误:
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
您可以解决:
sudo -H pip uninstall mysqlclient
sudo -H pip install --no-binary mysqlclient mysqlclient
次佳方法
如该线程所述,我最终找到了解决pip install --no-binary MySQL-python MySQL-python
问题的解决方案:Python’s MySQLdb can’t find libmysqlclient.dylib with Homebrewed MySQL
第三种方法
我遇到过同样的问题。我卸载并重新安装了MySQL-python:
pip uninstall MySQL-python
pip install MySQL-python