Possible Duplicate:
Way to have compiled python files in a separate folder?
When python compiles modules to bytecode, it produces .pyc files from your .py files.
My question is, is it possible to have these .pyc files written to a different directory than where the module resides?
For example, I have a large directory of modules. Rather than having it littered with .pyc files, I would like to keep my source code in the directory and have a subdirectory like "bytecode" where all of the .pyc are stored.
Is this possible?
Yes. so you can see, ALMOST same, decompile effect is VERY GOOD.
pyc files are placed in the same directory as the . py file. In Python 3.2, the compiled files are placed in a __pycache__ subdirectory, and are named differently depending on which Python interpreter created them. (This can be useful to people importing the same Python modules from multiple versions of Python.)
pyc files are created automatically by the GraalVM Python runtime when no or an invalid . pyc file is found matching the desired . py file. When a Python source file (module) is imported during an execution for the first time, the appropriate .
Basically all python files will be compiled to directory __pythoncache__ . jb.
This is answered in "Way to have compiled python files in a seperate folder?"
Short answer: No – unless you're running Python 3.2 or later – see here.
To clarify: Before 3.2, you can compile bytecode and put it elsewhere as per Brian R. Bondy's suggestion, but unless you actually run it from there (and not from the folder you want to keep pristine) Python will still output bytecode where the .py files are.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With