Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`sys.dont_write_bytecode` is True, but .pyc files are still generated

Tags:

python

I'm setting the PYTHONDONTWRITEBYTECODE environment variable to avoid .pyc files, and I have checked that sys.dont_write_bytecode is True.

But .pyc files are still generated everywhere.

PS: I'm using Python 2.6.6

The reason is that my script is running under env -i.

like image 967
satoru Avatar asked Mar 29 '12 01:03

satoru


2 Answers

It should appear before importing your modules. I have moved it to the top of code and it works.

#!/bin/python

import sys
sys.dont_write_bytecode = True

import myModule
like image 98
aminhotob Avatar answered Nov 10 '22 00:11

aminhotob


It could be that you are mispelling the env variable? PYTHONDONTWRITEBYTECODE

This works: PYTHONDONTWRITEBYTECODE=1 python -c "import test"

So does this: python -B -c "import test"

And when running a script directly which imports test.py: ./importer.py

importer.py

#!/usr/bin/env python -B

import test
like image 35
jdi Avatar answered Nov 10 '22 01:11

jdi