让 python MySQLdb 在 Ubuntu 上运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2198260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-04 00:02:27  来源:igfitidea点击:

Getting python MySQLdb to run on Ubuntu

pythonubuntu-9.10mysql

提问by greye

I created a virtualbox with a fresh install of ubuntu 9.10.

我使用全新安装的 ubuntu 9.10 创建了一个虚拟机。

I am trying to get MySQLdb to run on python but I'm failing at the import MySQLdb

我试图让 MySQLdb 在 python 上运行,但我失败了 import MySQLdb

I first tried sudo easy_install MySQL_python-1.2.3c1-py2.6-linux-i686.eggand then sudo apt-get install python-mysqldb.

我先试过了sudo easy_install MySQL_python-1.2.3c1-py2.6-linux-i686.egg,然后 sudo apt-get install python-mysqldb

Both apparently installed ok, but gave me the following error message when in python I have the import line:

两者显然都安装正常,但是在 python 中有导入行时给了我以下错误消息:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/MySQL_python-1.2.3c1-py2.6-linux-i686.egg/MySQLdb/__init__.py", line 19, in <module>

File "/usr/local/lib/python2.6/dist-packages/MySQL_python-1.2.3c1-py2.6-linux-i686.egg/_mysql.py", line 7, in <module>
File "/usr/local/lib/python2.6/dist-packages/MySQL_python-1.2.3c1-py2.6-linux-i686.egg/_mysql.py", line 6, in __bootstrap__
ImportError: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory

I have already installed MySQL and it is running, if that matters at all. I tried following this, but failed in step 2

我已经安装了 MySQL 并且它正在运行,如果这很重要的话。我尝试按照此操作,但在第 2 步中失败

采纳答案by Cristian

Your MySQLdb egg installation looks like it is not working properly. You should go into /usr/local/lib/python2.6/dist-packages and remove it.

您的 MySQLdb egg 安装看起来无法正常工作。您应该进入 /usr/local/lib/python2.6/dist-packages 并将其删除。

The Ubuntu python-mysqldb package should work fine. Unless you have a good reason, you should stick to your distribution's package manager when installing new software.

Ubuntu python-mysqldb 包应该可以正常工作。除非有充分的理由,否则在安装新软件时应该坚持使用发行版的包管理器。