Question

I'm getting the following error when I try to import regex.

Traceback (most recent call last):
  File "app.py", line 3, in <module>
    import regex 
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/regex.py", line 391, in <module>
    import _regex_core
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/_regex_core.py", line 21, in <module>
    import _regex
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/_regex.so, 2): no suitable image found.  Did find:
    /opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/_regex.so: mach-o, but wrong architecture

I've install python33 via macports and then installed the latest version of regex (by Matthew Barnett) via sudo python setup.py install.

I'm using Mac Os X Leopard (8.5). My processor is a Core 2 Duo which is 64 bit. How can I fix this error?

When I run lipo -info I get:

Non-fat file: /opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/_regex.so is architecture: i386

When I run lipo -info /opt/local/bin/python Non-fat file: /opt/local/bin/python is architecture: ppc7400

Why is python ppc7400?

Was it helpful?

Solution

MacPorts has its own port of the regex library for Python 3.3, so why not use that instead of building it yourself?

$ sudo port install py33-regex
[...]
$ python3.3
Python 3.3.0 (default, Nov 23 2012, 10:26:01) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import regex
>>> regex.match(r'[a-z]+', 'abc123').group(0)
'abc'

The ppc7400 architecture was better known as the PowerPC G4, which is one of the architectures supported by the version of OS X that you are running. It looks as if somehow you have managed to install a PowerPC build of Python 3.3. (Presumably it's running via Rosetta.)

One way that this could have happened is if you used to have a MacPorts installation on a PowerPC G4 machine, and you transferred your installation to your new Intel machine using Migration Assistant. See the MacPorts FAQ on the subject:

MacPorts works on both Intel- and PowerPC-based Macs, but, by default, the ports you install will be compiled only for the architecture you're currently running on. This means that if you migrate from, say, a PowerPC Mac to an Intel one and use Migration Assistant to copy your data to the new machine, you should reinstall all your ports on the new machine to rebuild them for Intel. See Migration for how to get things working again.

(Also, you don't need to use lipo: the file utility will tell you the architecture(s) in an executable or shared library.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top