pyc files not automatically compiled on import

Peter Otten __peter__ at web.de
Sun Jul 26 13:07:30 EDT 2009


Baz Walter wrote:

> i thought that python automatically compiled pyc files after a module is
> successfully imported. what could prevent this happening?
> 
> 
> Python 2.6.1 (r261:67515, Apr 12 2009, 03:51:25)
> [GCC 4.3.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import os
>  >>> os.mkdir('/home/baz/tmp/foo')
>  >>> os.chdir('/home/baz/tmp/foo')
>  >>> f = open('foo.py', 'w')
>  >>> f.write('print "hello world"\n')
>  >>> f.close()
>  >>> os.listdir('.')
> ['foo.py']
>  >>> import foo
> hello world
>  >>> os.listdir('.') # why no pyc file?
> ['foo.py']
>  >>> import py_compile
>  >>> py_compile.compile('foo.py')
>  >>> os.listdir('.')
> ['foo.py', 'foo.pyc']

You did not set the PYTHONDONTWRITEBYTECODE environment variable in a former 
life, or did you?




More information about the Python-list mailing list