0
votes

I keep getting the following error whenI run my python script,I have the "sudo apt-get install python-mysqldb" installed,i have tried to check if its installed by using "dpkg --get-selections | grep mysql" and check if mysqld is in the PATH,what am I missing here?how to debug this issue?

checking if mysqldb is installed

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

PATH:-

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

ERROR:-

Traceback (most recent call last):
  File "script.py", line 40, in <module>
    import MySQLdb
ImportError: No module named MySQLdb
1
what does which -a python output? - Padraic Cunningham
username@machinename:/local/mnt/workspace$ which -a python /usr/local/bin/python /usr/bin/python /usr/bin/X11/python - user3682248
ok then that is the problem, apt-get installs for usr/bin/python and you are using /usr/local/bin/python , try /usr/bin/python then import the module - Padraic Cunningham
@PadraicCunningham - how to install it in /usr/local/bin/python - user3682248
You should use pip, which python does pip point to? Or do you have pip installed? - Padraic Cunningham

1 Answers

0
votes

To use /usr/local/bin/python you can add the path to bashrc:

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

Then source .bashrc.

Download get-pip.py:

Then run python get-pip.py.

Finally run sudo pip install your_package

For system wide changes create a file /etc/profile.d/whatever.sh and add the export line to that.