即使已安装,也没有名为MySQLdb的模块错误

时间:2015-03-24 18:36:56

标签: python ubuntu path

当我运行我的python脚本时,我一直收到以下错误,我有" sudo apt-get install python-mysqldb"安装,我试图检查它是否通过使用安装 " dpkg --get-selections | grep mysql"并检查mysqld是否在PATH中,我在这里缺少什么?如何调试此问题?

检查是否安装了mysqldb

username@machinename:/local/mnt/workspace/cdit$ dpkg --get-selections | grep mysql
akonadi-backend-mysql                           install
libmysqlclient-dev                              install
libmysqlclient18                                install
libmysqlclient18:i386                           install
libqt4-sql-mysql                                install
libqt4-sql-mysql:i386                           install
mysql-client-core-5.5                           install
mysql-common                                    install
mysql-server-core-5.5                           install
python-mysqldb                                  install

路径: -

username@machine:/local/mnt/workspace$ echo $PATH
/pkg/wts/qct/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:/pkg/icetools/bin:/pkg/hwtools/bin:/pkg/netscape/bin:/pkg/gnu/bin:/prj/vlsi/tools/bin:/usr/bin/mysql:/usr/sbin/mysqld

错误: -

Traceback (most recent call last):
  File "script.py", line 40, in <module>
    import MySQLdb
ImportError: No module named MySQLdb

1 个答案:

答案 0 :(得分:0)

要使用/usr/local/bin/python,您可以添加bashrc的路径:

export PATH=/usr/local/bin/python:$PATH

然后source .bashrc

下载get-pip.py

然后运行python get-pip.py

最后运行sudo pip install your_package

对于系统范围的更改,请创建文件/etc/profile.d/whatever.sh并将导出行添加到该文件。