Python标准库在virtualen中不起作用

2024-04-16 08:28:26 发布

您现在位置:Python中文网/ 问答频道 /正文

以下是re.py的内容:

import re
if re.search('test', 'test'): print 'match'

当我运行$ python re.py时,输出显然是match。但当我激活一个virtualenv并再次尝试运行脚本时,我得到:

...
    if re.search('test', 'test'): print 'match'
AttributeError: 'module' object has no attribute 'search'

以下是当virtualenv不活动时Python解释器的输出:

$ 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

以下是激活时的输出:

$ 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

在virtualenv中使用python2.7.5时,re模块为什么会中断?你知道吗


Tags: pytestredefaultapplesearchifvirtualenv
1条回答
网友
1楼 · 发布于 2024-04-16 08:28:26

问题是re内部模块和re.py您的模块混合在一起。你知道吗

请将文件名更改为re_example.py,然后重试。你知道吗

相关问题 更多 >