Ubuntu 中的 Python-MySQLdb 错误
我正在尝试在 Ubuntu 中设置环境(从 MS-Windows)。 当然,它有Python 2.6。 我确实从“Ubuntu 软件中心”设置了 MySQL 5512 和 MySQLdb。
import dabo
import MySQLdb
工作正常。没有错误。
但是在建立连接时,提示不匹配 MySQLdb 和 MySQLdb 的版本_mysql。
ImportError: this is MySQLdb version (1, 2, 3, 'gamma', 1), but _mysql
is version (1, 2, 2, 'final', 0)
我该如何解决这个问题?
完整回溯---->
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "dabovmd/hotel.py", line 4, in <module>
empconn = dabo.db.dConnection(empci)
File "dabo/db/dConnection.py", line 32, in __init__
self._connection = self._openConnection(**kwargs)
File "dabo/db/dConnection.py", line 80, in _openConnection
return
self._connectInfo.getConnection(forceCreate=self._forceCreate, **kwargs)
File "dabo/db/dConnectInfo.py", line 105, in getConnection
return self._backendObject.getConnection(self, **kwargs)
File "dabo/db/dbMySQL.py", line 25, in getConnection
import MySQLdb as dbapi
File "/media/pyth/python26/Lib/site-packages/MySQLdb/__init__.py",
line 23, in <module>
(version_info, _mysql.version_info))
ImportError: this is MySQLdb version (1, 2, 3, 'gamma', 1), but _mysql
is version (1, 2, 2, 'final', 0)
提前致谢,
维尼特
I am trying to setup the environment in Ubuntu (making a shift from
MS-Windows).
It has, of course, Python 2.6.
I did setup MySQL 5512 and MySQLdb from 'Ubuntu Software Centre'.
import dabo
import MySQLdb
works OK. No error.
But while establishing a connection, is says that there is a mismatch in
versions of MySQLdb & _mysql.
ImportError: this is MySQLdb version (1, 2, 3, 'gamma', 1), but _mysql
is version (1, 2, 2, 'final', 0)
How do I solve this?
Complete traceback ---->
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "dabovmd/hotel.py", line 4, in <module>
empconn = dabo.db.dConnection(empci)
File "dabo/db/dConnection.py", line 32, in __init__
self._connection = self._openConnection(**kwargs)
File "dabo/db/dConnection.py", line 80, in _openConnection
return
self._connectInfo.getConnection(forceCreate=self._forceCreate, **kwargs)
File "dabo/db/dConnectInfo.py", line 105, in getConnection
return self._backendObject.getConnection(self, **kwargs)
File "dabo/db/dbMySQL.py", line 25, in getConnection
import MySQLdb as dbapi
File "/media/pyth/python26/Lib/site-packages/MySQLdb/__init__.py",
line 23, in <module>
(version_info, _mysql.version_info))
ImportError: this is MySQLdb version (1, 2, 3, 'gamma', 1), but _mysql
is version (1, 2, 2, 'final', 0)
Thanks in advance,
Vineet
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这看起来像是 MySQL 服务器和 python-mysqldb 之间的版本不匹配。
您使用的是哪个版本的 Ubuntu? (如果您最近转移了,请尝试使用 Ubuntu 11.04)。
解决问题的最简单方法是将 ubuntu 更新到至少 11.04,然后安装匹配版本的 mysql-server 和 python-mysqldb。
我使用的是 Ubuntu 11.04,我的 mysql-server 版本是 5.1.54-1ubuntu4,我的 python-mysqldb 版本是 1.2.2-10build2。
希望这有帮助
This seems like a version mismatch between your MySQL-server and your python-mysqldb.
Which version of Ubuntu are you using? (If you have recently shifted over, then try using Ubuntu 11.04).
The easiest way to solve your problem would be to update your ubuntu to atleast 11.04 and then to install matching versions of mysql-server and python-mysqldb.
I am using Ubuntu 11.04 and my mysql-server version is 5.1.54-1ubuntu4 and my python-mysqldb version is 1.2.2-10build2.
Hope this helps
这可能不适合您的需求,但我发现 MySQL Connector/Python 更容易设置高于 MySQLdb。它完全用Python实现,所以它不关心C接口库。
该解决方案有几个缺点。应该会慢一些更重要的是,就你的情况而言,我对 Dabo 一无所知,所以我不知道是否可以使用不同的 MySQL 接口。
This may not be suitable for your needs, but I've found MySQL Connector/Python to be much much easier to set up than MySQLdb. It's implemented entirely in Python, so it doesn't care about the C interface libraries.
This solution has a couple of downsides. It's supposed to be slower. And more importantly in your case, I know nothing about Dabo so I have no idea if it's possible to sub in a different MySQL interface.
似乎 apt-get 和 pip 都安装了自己版本的库。
尝试使用 sudo apt-get remove python-mysqldb 删除系统 mysql,然后
你应该有这样的东西:
正在读取包列表...完成
构建依赖树
读取状态信息...完成
以下软件包将被删除:
python-mysqldb
0 已升级,0 已新安装,1 已删除,3 未升级。
执行此操作后,将释放 196 kB 磁盘空间。
您想继续吗? [是/否] 是
(正在读取数据库...当前安装的 109333 个文件和目录。)
正在删除 python-mysqldb (1.2.3-2ubuntu1) ...
It seems that each of apt-get and pip installed their own version of the library.
Try removing system mysql with
sudo apt-get remove python-mysqldb
, andyou should have something like this:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
python-mysqldb
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
After this operation, 196 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 109333 files and directories currently installed.)
Removing python-mysqldb (1.2.3-2ubuntu1) ...
请不要执行上面建议的操作...
在 MySQLdb 文件夹中使用以下命令:
Please don't do what has been suggested above...
use these commands in your MySQLdb folder: