[Tutor] when is "pythondontwritebytecode" useful?

Albert-Jan Roskam fomcl at yahoo.com
Tue Jan 21 20:44:55 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


Hi Oscar, Eryksun,

Thanks for your replies. Good general tip to check the big tracker. Somehow Duckduckgo or Google did not find that page. Glad to read that I was sort of right: "Currently python tries to write the .py[co] files even
in situations, where it will fail, like on read-only
mounted file systems."

>> 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.

Hmmm, number of OS * number of Python versions = a lot of packages. Isn't a .zip file easiest? Or maybe msi or wininst*) on Windows and .deb on Linux (with alien that can easily be converted to e.g. rpm).

*) Last time I tried creating a wininst under Linux it created an .exe file of correct/plausible size, but with a huge traceback. Never bothered to try if it did work. Maybe it was this: http://bugs.python.org/issue8954. The bug tracker is a useful source of information indeed. ;-)

regards,
Albert-Jan


More information about the Tutor mailing list