Not sure how to explain it and can’t seem to figure out why this is happening but I tried to install ‘MySQLdb’ from macports.
When I type ‘python’ and import MySQLdb, then it fails but when I launch python from /opt/local/bin/python2.7 and do the same then it works perfectly. I thought I’d be smart and see where the default python is pointing to and then point it to this one but thats when it starts getting strange.
$ which python
/opt/local/bin/python
$ ls -l /opt/local/bin/python
lrwxr-xr-x 1 root admin 24 Feb 13 13:55 /opt/local/bin/python -> /opt/local/bin/python2.7
I don’t understand, it seems to be pointing the the one that works but I can’t load the same module as I can when I open python with the full path.
I’m sure I’m doing something dumb, so any help to explain why this is happening would be great.
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: No module named _mysql
The Python version banner you show is from yet another Python, that of the python.org 2.7.2 64-bit/32-bit installer downloaded from python.org. It is not a MacPorts Python. There should be a symlink to it at
/usr/local/bin/python2.7. Apparently, the PATH environment variable in the terminal session you are using is not what you think it is or possibly you have a shell alias defined. Try:You need to ensure that the MacPorts Python directory (
/opt/local/bin) comes before that of the python.org Python (/Library/Frameworks/Python.frameworks/Version/2.7/binor/usr/local/bin).UPDATE: Also check the current value of the MacPorts
port selectcommand. It may be pointing at a non MacPorts Python.