I installed python 2.7 with python brew. How do I install packages to work with it? I installed MySQLdb with synaptic, but I am unable to import it in python 2.7.
4 Answers
Switch to 2.7:
pythonbrew switch 2.7
Curl and run get-pip to get the correct version of pip for 2.7:
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
python get-pip.py
This will install the version of pip for 2.7. Check it by doing:
pip --version
Turn off pythonbrew:
pythonbrew off
Check the version of pip again, and it should be using the one for your default Python:
pip --version
If all is good, then switch back to 2.7 in pythonbrew and install mysql-python for 2.7:
pythonbrew switch 2.7
pip install mysql-python
Check to see that it is installed for 2.7:
pip freeze
Pip freeze will give you a listing of all installed libraries for the current active version of Python.

- 111
- 6
You should try to install pip, which is a recursive acronym: Pip Installs Packages. This thread talks about installing it on windows, on Ubuntu I did sudo apt get install pip.
Ok, your problem is that "mysqldb" is not a python package. You need to use MySQLdb as a backend, or simply install sqlite3 and import that into Python, which is a module that mimics SQL. If you end up using an actual full-on database, like MySQLdb
or PostgreSQL
, you'll probably need to install SQLAlchemy
, which is a Python module to interface with those.
-
-
1
-
Do other packages install correctly? Try BeautifulSoup or something if you don't have that already, which should be available through pip. – rofls Aug 16 '12 at 06:50
-
BeautifulSoup did get installed. But I still cannot import it in 2.7. It installs to default python dist that comes with ubuntu (2.65) . – ElKamina Aug 16 '12 at 06:57
-
Regarding mysqldb not being a python package, I am not sure. I can install it using synaptic and I can import it in python 2.65 (default python) – ElKamina Aug 16 '12 at 06:59
-
Hmmm. Ok, forget the Soup, see my above modifications and try installing sqllite3, if you're ok with testing that. As far as I experienced they're very similar on the front-end, so it's definitely fine for troubleshooting and just getting started. – rofls Aug 16 '12 at 07:00
-
Ok, try using `switch
` and then installing it, if you haven't already. Otherwise you're just installing it to your original version, Python 2.65, as pip is assigning it to your active version of Python. – rofls Aug 16 '12 at 07:09
You need to install a version of pip for each Python version. Do you have easy install available? If so you can do
easy_install-2.7 pip
Is there a specific reason that you are installing Python via home brew though? You do know that Ubuntu has as a package.
sudo apt-get install python2.7
Will give you a version of Python that is already nicely set up.
I also believe that you should be trying to install the Python package called mysql-python.
pip install mysql-python
MySQLDB is not a Python package. It's the actual database.

- 24,871
- 8
- 79
- 83
Agree with @leta-rogers. However, I didn't have to install pip separately. Installing python using pythonbrew installed pip (for python 2.7) for me as well:
pythonbrew install 2.7
pythonbrew switch 2.7
pip install mysql-python

- 762
- 5
- 21