virtualenv中的日志记录模块

时间:2016-02-23 22:19:41

标签: python logging virtualenv

Ubuntu 12.10

在试图让flask + logging在virtualenv中工作时,我发现似乎日志模块没有从virtualenv导入(下面的代码片段中的最后一行)。

(我认为当我的烧瓶应用程序在virtualenv中运行时,这会产生不打印到日志文件的副作用,但如果这个问题没有帮助,我会单独询问)

这是为什么?记录模块是否有点特殊?

# system python
# imports come from /usr/lib/python2.7 as expected

me@home:~/Desktop$ python
Python 2.7.3 (default, Apr 10 2013, 05:13:16) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re; print re
<module 're' from '/usr/lib/python2.7/re.pyc'>                          # OK
>>> import logging; print logging
<module 'logging' from '/usr/lib/python2.7/logging/__init__.pyc'>       # OK
>>> exit()

# make virtual env

me@home:~/Desktop$ virtualenv --version
14.0.0
me@home:~/Desktop$ virtualenv testenv
New python executable in /home/me/Desktop/testenv/bin/python
Installing setuptools, pip, wheel...done.

# Try again inside venv

me@home:~/Desktop$ source testenv/bin/activate
(testenv) me@home:~/Desktop$ python
Python 2.7.3 (default, Apr 10 2013, 05:13:16) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re; print re
<module 're' from '/home/me/Desktop/testenv/lib/python2.7/re.pyc'>     # OK!
>>> import logging; print logging
<module 'logging' from '/usr/lib/python2.7/logging/__init__.pyc'>      # WHY?

1 个答案:

答案 0 :(得分:1)

Python标准库中的大多数模块不会复制到virtualenv - 只有少数几个是virtualenv正常运行所需的。所以你所看到的是正常的。