Here are the contents of re.py
:
import re
if re.search('test', 'test'): print 'match'
When I run $ python re.py
, the output, obviously, is match
. But when I activate a virtualenv and try to run the script again, I get:
...
if re.search('test', 'test'): print 'match'
AttributeError: 'module' object has no attribute 'search'
Here's the output of the Python interpreter when the virtualenv is not active:
$ python
Python 2.7.5 (default, Jun 3 2013, 17:42:22)
[GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.57))] on darwin
And here's the output when it's active:
$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Why does the re
module break when using Python 2.7.5 inside the virtualenv?
The problem is re
internal module and re.py
your module mixed.
Please change your file name to re_example.py
and try.