virtualenv, mysql-python, pip: anyone know how?

33,838

Solution 1

I'm also trying to setup MySQL bindings in a virtualenv. All I had to do was install the package that contains mysql_config. On Ubuntu it's called libmysqlclient-dev.

After that I was able to do a (virtualenv'd) python setup.py build and python setup.py install.

Solution 2

In OS X I had used Macports to install my MySQL, which made the mysql_config file be called mysql_config5.

So I did: sudo ln -s mysql_config5 /opt/local/bin/mysql_config

And then ran pip install MySQL-python from a virtualenv and all was fine.

Solution 3

You may not have mysql_config at all if you don't have the appropriate mysqlclient-dev OS package installed.

Personally, for packages that require extensive C compilation, I prefer to install OS-packaged versions, as I've had fewer problems that way. It's easier to install the OS-packaged version of mysql-python on all my servers than it is to install the compilation dependencies.

Fortunately in my experience those packages also tend to be very stable (mysql-python, PIL, lxml, etc), so I don't need to version-pin them per-project.

It does, however, prevent me from using virtualenv --no-site-packages, which is a little annoying.

Share:
33,838
rz.
Author by

rz.

web-developer and startup dude. i make http://idonethis.com Say hi: [email protected]

Updated on October 12, 2020

Comments

  • rz.
    rz. over 3 years

    I'm trying to install the mysql bindings in a virtualenv. I'd prefer to use pip or easy_install. pip gives me the following error:

      File "setup_posix.py", line 24, in mysql_config
    
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    
    EnvironmentError: mysql_config not found
    

    easy_install either gets a 404 from sourceforge or gives me a very similar error.

    Does anyone know how to get around this in a virtualenv?

  • Density 21.5
    Density 21.5 over 13 years
    In order to make this work I also had to install python-dev before doing the setup.py build and install.
  • stricjux
    stricjux over 13 years
    After libmysqlclient-dev I used PIP to install the mysql binding: "pip install MySQL-python"
  • Anne
    Anne over 12 years
    Comment by anonymous user: On Fedora it's called mysql-devel, i.e. sudo yum install mysql-devel. After that, pip install mysql-python works in the virtualenv.
  • Kirk Woll
    Kirk Woll almost 12 years
    For me, the command to do that was: export PATH=$PATH:/usr/local/mysql-5.5.24-osx10.6-x86_64/bin on MAC OSX. Your mileage may vary, but just do a locate mysql_config and you should be in business.
  • DarthOpto
    DarthOpto about 10 years
    Thanks @Anne this worked beautifully.