Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > pyc files not automatically compiled on import

Reply
Thread Tools

pyc files not automatically compiled on import

 
 
Baz Walter
Guest
Posts: n/a
 
      07-26-2009
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']

 
Reply With Quote
 
 
 
 
Fuzzyman
Guest
Posts: n/a
 
      07-26-2009
On Jul 26, 5:22*pm, Baz Walter <(E-Mail Removed)> 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
--
http://www.ironpythoninaction.com/
 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      07-26-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?

 
Reply With Quote
 
Baz Walter
Guest
Posts: n/a
 
      07-26-2009
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

 
Reply With Quote
 
Aahz
Guest
Posts: n/a
 
      07-27-2009
In article <(E-Mail Removed)>,
Baz Walter <(E-Mail Removed)> 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 ((E-Mail Removed)) <*> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Module baldy compiled to pyc? Laszlo Nagy Python 1 09-27-2012 11:13 AM
Out-dated compiled modules (*.pyc)? Anastasios Hatzis Python 3 08-26-2006 08:03 PM
Embedding Python: How to run compiled(*.pyc/*.pyo) files using Python C API? Shankar Python 1 05-05-2006 08:32 AM
Prevent pyc or pyo compiled output Jason Smith Python 2 06-25-2004 10:51 AM
Not all .PY files are compiled to .PYC during execution Tony C Python 2 02-13-2004 04:28 AM



Advertisments