0

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?

Baz
  • 12,713
  • 38
  • 145
  • 268
  • Are you sure you're using the 3.3 python binary? – Xymostech Mar 24 '13 at 21:48
  • Look at the library paths: this strongly indicates that Python 3.3 is being run. – Gareth Rees Mar 24 '13 at 21:50
  • When I run python on the terminal, I get: Python 3.3.0 (default, Mar 24 2013, 16:14:43) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> – Baz Mar 24 '13 at 22:02

1 Answers1

2

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.)

Gareth Rees
  • 64,967
  • 9
  • 133
  • 163
  • I installed regex with macports and now it imports correctly. However, that's because it is now also built for the ppc7400 architecture. Why is this? – Baz Mar 24 '13 at 22:01
  • I haven't migrated from PowerPC. :) – Baz Mar 24 '13 at 22:10
  • What settings do you have for `build_arch` and `universal_archs` in `/opt/local/etc/macports/macports.conf`? – Gareth Rees Mar 24 '13 at 22:12
  • In macports.conf I have: 'universal_archs ppc i386' but no mention of build_arch. – Baz Mar 24 '13 at 22:16
  • You could try setting `universal_archs` to `x86_64 i386` and then uninstalling and re-building the `python33` port with the `+universal` option. Or read the MacPorts docs some more... – Gareth Rees Mar 24 '13 at 22:18