[Tutor] when is "pythondontwritebytecode" useful?

eryksun eryksun at gmail.com
Mon Jan 20 23:08:07 CET 2014


On Mon, Jan 20, 2014 at 5:42 AM, Albert-Jan Roskam <fomcl at yahoo.com> wrote:
>
> When is setting a PYTHONDONTWRITEBYTECODE environment variable useful? Or
> set sys.dont_write_bytecode to True? Or start Python with the -B option?
> I know what it does
> (http://docs.python.org/2/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE),
> i.e. no pyc or pyo fiules are written, but WHY is that sometimes a good
> thing? The only useful scenario I can think of is when you don't have write
> rights to create pyc files but you want to use a package anyway.

The bug tracker can provide insight into why a given feature exists,
or why it's implemented a certain way:

Issue 602345: option for not writing .py[co] files
http://bugs.python.org/issue602345

> However, I recently opened an EGG file with a zip utility (because I knew
> egg uses zipimport so it's a zip-like format) and I noticed that there
> were .pyc files.

Eggs are a binary distribution format. They contain byte-compiled .pyc
files and extension modules. There's even an option to exclude .py
source files. The filename should indicate the Python version and
platform.

Loading extension modules directly from an egg depends on the
pkg_resources module from setuptools. The modules are extracted to a
local cache directory. On Windows the default cache directory is
"%APPDATA%\Python-Eggs", else it uses "~/.python-eggs". You can
customize this with the environment variable PYTHON_EGG_CACHE.


More information about the Tutor mailing list