Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can compiled bytecode files (.pyc) get generated in different directory? [duplicate]

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?

like image 803
Corey Goldberg Avatar asked Mar 04 '09 19:03

Corey Goldberg


People also ask

Can PYC files be decompiled?

Yes. so you can see, ALMOST same, decompile effect is VERY GOOD.

Where are .PYC stored?

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.)

How are PYC files generated?

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 .

Where do compiled Python files go?

Basically all python files will be compiled to directory __pythoncache__ . jb.


1 Answers

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.

like image 111
mikl Avatar answered Nov 11 '22 06:11

mikl