FAQ
hello

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']

Search Discussions

  • Fuzzyman at Jul 26, 2009 at 4:44 pm

    On Jul 26, 5:22?pm, Baz Walter wrote:
    hello

    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']
    Works for me I'm afraid (Mac OS X and Python 2.6).

    Michael Foord
  • Peter Otten at Jul 26, 2009 at 5:07 pm

    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?
  • Baz Walter at Jul 26, 2009 at 7:30 pm

    Peter Otten wrote:
    You did not set the PYTHONDONTWRITEBYTECODE environment variable in a former
    life, or did you?
    thanks peter

    no i didn't, but i've just discovered a script in /etc/profile.d that
    did. now i'll have to try to find out how that script got in there :-|
  • Aahz at Jul 27, 2009 at 2:45 pm
    In article <mailman.3739.1248625343.8015.python-list at python.org>,
    Baz Walter wrote:
    i thought that python automatically compiled pyc files after a module is
    successfully imported. what could prevent this happening?
    Looks like you got your problem fixed, but for the record, not having
    write permission on a directory also causes this. It's even uglier when
    the .pyc already exists but does not have write perms.
    --
    Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/

    "Many customs in this life persist because they ease friction and promote
    productivity as a result of universal agreement, and whether they are
    precisely the optimal choices is much less important." --Henry Spencer

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJul 26, '09 at 4:22p
activeJul 27, '09 at 2:45p
posts5
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase