Use Pycache Prefix to Move pyc Files out of Your Source Code Starting in Python 3.8
If you've been working with Python for a while, you've probably noticed .pyc
files in your source code. In fact, you've probably got a line like *.pyc
in your .gitignore
file to prevent checking them in.
These pyc
files are called "compiled bytecode", and they are generated by the Python interpreter any time a .py
file is imported. This happens because Python libraries/modules are often imported more than once by a program, and there's no reason to re-compile the file every time.
In some environments there are issues related to having pyc files in the source code, and one proposed solution involved designating a separate, parallel filesystem, outside of the source code that can be used to cache compiled bytecode. This feature was included in Python 3.8, and in this guide we'll learn how to use it.