pyc files not automatically compiled on import

B

Baz Walter

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

Fuzzyman

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
 
P

Peter Otten

Baz said:
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?
 
B

Baz Walter

Peter said:
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 :-|
 
A

Aahz

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 ([email protected]) <*> 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top