Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logging module in virtualenv

Ubuntu 12.10

While trying to get flask+logging to work in a virtualenv, I discovered that it seems the logging module is NOT getting imported from the virtualenv (last line in snippet below).

(I think this is having the side effect of not printing to the log file when my flask app is run inside a virtualenv, but I'll ask that separately if this question doesn't help)

Why is this?? Is the logging module somehow special?

# 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?
like image 227
obk Avatar asked Feb 23 '16 22:02

obk


1 Answers

Most modules in the Python standard library are not copied to the virtualenv - only the select few which are needed for the virtualenv to function correctly. So what you are seeing is normal.

like image 102
Vinay Sajip Avatar answered Oct 04 '22 02:10

Vinay Sajip