ElKamina
ElKamina

Reputation: 7807

installing packages over pythonbrew

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.

Upvotes: 2

Views: 3223

Answers (4)

mandark
mandark

Reputation: 782

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

Upvotes: 0

Leta
Leta

Reputation: 111

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.

Upvotes: 6

aychedee
aychedee

Reputation: 25579

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.

Upvotes: 0

rofls
rofls

Reputation: 5115

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.

Upvotes: 0

Related Questions