Forums

Problem setting up mySQL database in Pyramid App - mysql_config error

I am trying to install mysql-python on my virtualenv and am getting a mysql_config not found error.

After reading this forums answer to the same problem, I realized that I am getting the error because I installed the virtual environment with --no-site-packages.

The solution given is to install with the site packages. Pyramid documentation says that it is important to install the virtualenv with no site packages for pyramid to work properly. So I'm trying to figure out how to get mysql working with my current installation.

Here are my thoughts on options, if anyone can lend their input I'd be thankful!

Solution 1: Uncomment mysql_config - /usr/local/bin/mysql_config and update the path. the problem with this is that I don't know if it is good practice to do this, if it will solve my error or not and what the actual path to mysql_config is.

The second solution is on the link above and involves creating symbolic links. They say "To find the links that need to be made you can consult the egg description in the file /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.4-py2.7.egg-info/installed-files.txt"

But I can't find this file, it doesn't seem to exist.

Anyone run into this problem, who can help?

Looks like the path should be this:

/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4-py2.7.egg-info/installed-files.txt

You'll need to link those files into the right place in your virtalenv.

I do actually have an experimental script I wrote a little while ago which attempts to copy (not link) files from a specified package in the external environment. If you're happy to accept that it's not very heavily tested and there's a risk it'll do strange things, you're welcome to give it a try. You can get a copy from this gist.

I've just briefly tried it with MySQLdb on PA and it seems to work (I can connect to my MySQL DB and make queries), but I can't make any promises. I invoked it as follows (you must run it from outside your virtualenv):

~/bin/clonepkg.py mysqldbtest MySQL-python

... Where mysqldbtest is the name of my virtualenv (you'll need to replace that with your own) and MySQL-python is the official name of the package.

If you do want to use this script, I strongly suggest using it a new virtualenv where you haven't lost any work if it does the wrong thing. Also, I suggest running with --dry-run first and looking carefully at what it's about to do. The result of this command should actually be a list of shell commands which achieve the same effect, so if you're happy using that to create a shell script, examining it and then running it then by all means do that instead.

Thanks for all the helpful advice Cartroo - much appreciated.

I set up the symbolic links, but nothing seemed to change, still can't install mysql-python (same error about not finding the mysql_config) Is there anything I should do after creating the sym links?

I also tried running the script and I couldn't get it to run - I'm just learning how to work with python and I'm struggling with understanding where to put things and I think that is causing my issue - I'll keep trying!

Also, for clarity's sake, could anyone tell me why I can't find a mysql_config when I use: find / -name mysql_config - does it just not exist, should it?, do I need to install something else? My understanding of my problem is that I need to install mysql-python so that I can connect to the already existing mysql package which should have a mysql_config in it (sorry if I'm totally wrong about what's going on, but do let me know)

Hello,

You could try symlinking the required MySQLdb packages into your virtualenv. If you cd into <your virtualenv>/lib/python2.7/site-packages

Then try:

ln -s /usr/local/lib/python2.7/site-packages/MySQLdb/ MySQLdb
ln -s /usr/local/lib/python2.7/site-packages/_mysql_exceptions.py _mysql_exceptions .py
ln -s /usr/local/lib/python2.7/site-packages/_mysql.so _mysql.so

This means that your imports will work but it does not include ALL of site packages inside your virtualenv.

Hi Hansel - thanks! I ended up bypassing the problem by using mysql-connector-python instead of mysqldb. Once I connected that way, it worked perfectly.

For anyone wanting to do things this way: 1. Add mysql-connector-python to your pyramid setup.py dependencies or install it using pip 2. change your sqlalchemy.url from mysql:username:password@server/database to mysql+mysqlconnector:username:password@server/database (myql+mysqlconnector is literal, the other items need to be filled in by you)

Thanks to all - your answers taught me a lot!