Home > python > How to avoid *.pyc files?

How to avoid *.pyc files?

Your project directories are littered with .pyc files. How to tell the interpreter to stop creating them?

Since Python 2.6:

“Python can now be prevented from writing .pyc or .pyo files by supplying the -B switch to the Python interpreter, or by setting the PYTHONDONTWRITEBYTECODE environment variable before running the interpreter. This setting is available to Python programs as the sys.dont_write_bytecode variable, and Python code can change the value to modify the interpreter’s behaviour.” (tip from here)

So I added the following lines to my .bashrc file:

# don't create .pyc and .pyo files

Python 3.2 can save .pyc files in a dedicated subfolder called “__pycache__“.

Categories: python Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: