Frage

My system: Mac OS X 10.6.8, gcc 4.2, python 2.7, xcode 3.2.3

I use python 2.7 and I got error when tried to do: import objc, it returns: ImportError: No module named objc.

It looks like the objc module is not there. But actually I have the objc module installed already. Snow Leopard has got pyobjc preinstalled and I have also checked this using python2.6 (I have python 2.7 and 2.6 in my Mac). So if I invoke import objc using python2.6, I got no error which means objc exists and I can use that module without problems ... but if I import using python 2.7, I will got the ImportError: No module named objc error.

Does anyone have any solution? FYI, the python2.6 is coming preinstalled with OS X while 2.7 is manually installed. I've been using the 2.7 for couple of months without problems.

War es hilfreich?

Lösung

Python C extension modules like objc cannot be re-used between python versions. You'll have to install the objc module for 2.7 separately.

Generally, different python installations (such as 2.6 or 2.7, or 3.2) use separate module import locations, and you normally install extensions per python setup.

Andere Tipps

In general, packages installed with one python installation are not available to other python installations. You can make them available by messing with sys.path (or by setting PYTHONPATH in your environment) and installing your modules to a common place, however, as pointed out by @MartijnPieters, if it is a C extension, you'll need to re-build the module for python 2.7 (and then you can't put it in a common place). Usually, this is as easy as:

<sudo> python2.6 setup.py install #install for python 2.6
<sudo> python2.7 setup.py install #install for python 2.7

since the command python is generally just a (soft) link to your preferred python installation.

sudo may or may not be necessary depending on where your python implementations live on your path.

This works for pure python modules too by the way. Since the source code generally doesn't take up too much space, this may be a good way to install all your modules if you'll be switching back and forth between python 2.6 and python 2.7.

The same thing goes if you're using easy_install to install your packages:

easy_install-2.6 somepackage
easy_install-2.7 somepackage
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top