4

I recently started getting the following error in my trac install:

Cannot load Python bindings for MySQL

I, unfortunately, had to reinstall MySQL, and, afterwards, I started getting those issues. I have spent the last hour trying to track something down on Google, but I couldn't get anything to work. I made sure MySQL is up and running correctly. I created a new MySQL user specific to trac. I made sure all of the packages are there there. Nothing.

Here's my dkpg (I run Ubuntu Maverick):

dpkg -l | grep python

  • libapache2-mod-python
  • libapache2-mod-python-doc
  • libpython2.6
  • libpython3.1
  • python
  • python-central
  • python-docutils
  • python-genshi
  • python-imaging
  • python-lxml
  • python-minimal
  • python-mysqldb
  • python-pkg-resources
  • python-pybabel
  • python-pygments
  • python-roman
  • python-setuptools
  • python-subversion
  • python-support
  • python-tz
  • python2.6
  • python2.6-minimal
  • python3.1
  • python3.1-minimal

If anyone has any ideas as to what it could be, I'd be forever grateful.

Sebastian Frohm
  • 418
  • 5
  • 16

2 Answers2

1

That error should result when Trac tries to do "import MySQLdb" but it fails. You do have the right package in place which should provide that module, but for some reason it's failing. To find out why, you should look at the environment in which Trac is running. Is it using a Python other than /usr/bin/python2.6? Does it have a $PYTHONPATH set?

You may also want to try importing MySQLdb directly:

/usr/bin/python2.6 -c 'import MySQLdb'

That should have no output if the package can be loaded as expected.

Lastly, this may not be related, but you know that Maverick is no longer supported, right? It won't get any security updates or other support from Ubuntu.

Edit:

The python2.6 import worked fine, so we need to look closer at the trac environment. One way to do this will be to edit the db/mysql_backend.py file and insert some debugging information. (If this is an OS-packaged install, you should find that file under /usr/lib/python2.6/dist-packages/trac/; otherwise, you probably know where you put it). Let's try changing the MySQLConnector.get_supported_schemes() method, since I'm not sure where plain prints will show up for you.

def get_supported_schemes(self):
    if not has_mysqldb:
        import sys
        self.error = "Cannot load Python bindings for MySQL. sys.path = %r, sys.executable = %r" \
                     % (sys.path, sys.executable)
    yield ('mysql', -1 if self.error else 1)
the paul
  • 8,972
  • 1
  • 36
  • 53
0

instead of calling a specific python install like the paul is suggesting, try this at your terminal:

launch the path's python instance

python

see if you can import mysqldb

import MySQLdb

also run for us a:

pip freeze

we should see a mysql-python in the output

Francis Yaconiello
  • 10,829
  • 2
  • 35
  • 54
  • The import yielded no errors or any output, so I'm going to assume it's all good. pip freeze gave me: Warning: cannot find svn location for TracAccountManager==0.4dev-r11350 Babel==0.9.4 Genshi==0.6 MySQL-python==1.2.2 PIL==1.1.7 Pygments==1.3.1 Trac==0.12 ## FIXME: could not find svn URL in dependency_links for this package: TracAccountManager==0.4dev-r11350 TracGit==0.12.0.5dev distribute==0.6.14 docutils==0.6 lxml==2.2.6 mod-python==3.3.1 pytz==2010b wsgiref==0.1.2 Could it be the TracAccountManager? – Sebastian Frohm Jul 13 '12 at 04:12
  • it seems that if you can load MySQLdb than thats not the real problem. Have you tried backing up your db and reinstalling trac? It could be that trac when compiling/setting up, hard links to a previous version of the python-mysql binding, when you uninstalled it lost reference, and because you didn't reinstall trac it doesn't know about the new install of mysql? (kinda guessing, but that would be my next step) – Francis Yaconiello Jul 13 '12 at 13:08
  • That was pretty much my game plan. I backed up the db before I even put anything out here, just in case I could not fix the issue, and had to resort to reinstalling trac. – Sebastian Frohm Jul 13 '12 at 14:11
  • I ended up dumping the DB, and recreating the instance. The issue seems to have cleared itself up. Thanks for your help! – Sebastian Frohm Jul 16 '12 at 15:40