Is the default configuration of re incorrect on macbooks? Or have I simply misunderstood something?
Question: Python came pre-installed on my macbook and I have been slowly getting
acquainted with the langauge. However, it seems that my configuration of the
re library is incorrect, or I simply misunderstand something and things are
amiss. Whenever I run a python script with "import re", I recieve the
following error:

    
    
    Traceback (most recent call last):
      File "regex.py", line 2, in <module>
        import re
      File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/re.py", line 4, in <module>
        # re-compatible interface for the sre matching engine
    AttributeError: 'module' object has no attribute 'compile'
    

What gives!


Answer: Pretty mysterious problem, given that line 4 in that file (and many other
lines around that line number) is a comment (indeed the error msg itself shows
that comment line!-) so even with the worst misconfiguration I'd be hard put
to reproduce the problem as given.

Let's try to simplify things and check how they may (or may not) break. Please
open a Terminal, mkdir a new empty directory somewhere and cd into it (so we
know there's no filename conflict wrt modules etc), at the bash prompt `unset
PYTHONPATH` (so we know for sure that isn't interfering), `unset
PYTHONSTARTUP` (ditto); then type the command:

    
    
    $ python -c'import re; print re.__file__'
    

It should emit the line:

    
    
    /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/re.pyc
    

does it? If so, then we can keep rooting around to understand what name clash
(or whatever) caused your original problem. If the problem persists under such
"clean" conditions then your system is jinxed and I would reinstal Mac OS X
Leopard if I were in your shoes!

