How to Prevent Python from Generating .pyc Files
Python typically compiles source code (.py files) into bytecode (.pyc files) to enhance execution speed. However, you may encounter instances where you prefer to execute the interpreter without creating .pyc files.
According to "What's New in Python 2.6 - Interpreter Changes," you can suppress the creation of .pyc or .pyo files by using the following methods:
Run your program using the syntax: python -B prog.py. The -B switch prevents the generation of bytecode.
Set the PYTHONDONTWRITEBYTECODE environment variable to 1 before executing the interpreter. This setting is reflected in the sys.dont_write_bytecode variable within Python programs, allowing you to alter the interpreter's behavior dynamically.
Additional Considerations:
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3