Calvin's

Icon

designs and hacks. people and products.

Python 2.7 via MacPorts

I have recently upgraded to use Python 2.7 on my Mac for local development work for a python/django project and needed to use py27-mysql.  So naturally, this is what I did…

calvin$ sudo port -v install python27
calvin$ sudo python_select python27
calvin$ sudo port -v install py27-setuptools

Unfortunately when I attempted to install py27-mysql via MacPorts, this is the error I received:

calvin$ sudo port -v install py27-mysql
--->  Computing dependencies for py27-distribute.Error: Unable to execute port: Can't install py27-distribute because conflicting ports are installed: py27-setuptools
To report a bug, see <http://guide.macports.org/#project.tickets>

It appears that py27-mysql needs to use py27-distribute instead of py27-setuptools.

To solve this problem, I decided to uninstall py27-setuptools and give py27-distribute a spin.  So:

calvin$ sudo port -v uninstall py27-setuptools
--->  Deactivating py27-setuptools @0.6c11_1
--->  Uninstalling py27-setuptools @0.6c11_1
--->  Uninstall is removing py27-setuptools from the port registry.
calvin$ sudo port -v install py27-mysql
--->  Computing dependencies for py27-mysql..
--->  Dependencies to be installed: py27-distribute
--->  Fetching py27-distribute
--->  Verifying checksum(s) for py27-distribute
--->  Checksumming distribute-0.6.15.zip
--->  Extracting py27-distribute
--->  Extracting distribute-0.6.15.zip
--->  Configuring py27-distribute
--->  Building py27-distribute
...
running install_egg_info
running egg_info
writing MySQL_python.egg-info/PKG-INFO
writing top-level names to MySQL_python.egg-info/top_level.txt
writing dependency_links to MySQL_python.egg-info/dependency_links.txt
deleting MySQL_python.egg-info/native_libs.txt
reading manifest file 'MySQL_python.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'MySQL_python.egg-info/SOURCES.txt'
Copying MySQL_python.egg-info to /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py27-mysql/work/destroot/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MySQL_python-1.2.2-py2.7.egg-info
running install_scripts
--->  Installing py27-mysql @1.2.2_0+mysql5
--->  Activating py27-mysql @1.2.2_0+mysql5
--->  Cleaning py27-mysql
--->  Removing work directory for py27-mysql

And magically, py27-mysql now works as required.

Hurrah. :-)

No module named mysqldb

Python MySQL on Mac

Attempting to run a python/django application today which depended on a legacy MySQL db, I encountered:

No module named mysqldb

Apparently, I am missing the python interface library to MySQL, so here’s the easy solution to it:

sudo port -v install py26-mysql

WARNING: The download and installation process could take a while! :-)  About 30 minutes for my case.

As I was using Python 2.6.4 previously, the installation process also upgraded my Python to 2.6.6 since py26-mysql depends on the Python 2.6.6.

Back to coding!

Multiple versions of Python on Mac with Macports

Python on Mac!Linux users would be familiar with “aptitude” as our virtual swiss army knife to install useful open source packages and software.

The bash command:

sudo aptitude install [package name]

gets us what we want most of the time.  Some less-common software library requires more tweaking and our manual intervention to make and build of course, but in general “aptitude” suffices.

Read the rest of this entry »