Encapsulation is the hiding of an implementation in OOP the way I understand it. I searched on Google and I was thinking of trying to write a program to test, but my tests would only happen at run time. Python allows you to hide methods with "__" syntax. Java allows you to hide member variables with the "private" keyword. Does this hiding happen at compile time or run time?
Encapsulation is a design principle. It's about writing software, has nothing to do with running or compiling software.
To address the two concrete questions:
For the main implementation of Python (CPython), there is no "compile time", because it isn't compiled.
Python methods are really just data structures. When the interpreter is reading through a source file and runs into a method, it just creates a new entry in the relevant Class' method table, which maps method names to the method implementation. The definition of a double underscored method just declares this entry in a different way, so that it can't be overloaded by a subclass in the regular way.
In Java, the
privatekeyword is just used to communicate to the compiler. Once the compiler learns that you want a method to be private, it'll enforce a certain set of rules around its usage. This metadata does also end up encoded into the byte code, so reflection mechanisms can that the method is
Encapsulation is a multi-layered concept. On some lower level it can be interpreted as something having to do with "private" modifiers and not having access to some variable at runtime (so short answer: both). This interpretation is somewhat useless however.
To help with complexity and maintainability, encapsulation needs to be interpreted at a much higher level. What I mean is that encapsulation means to encapsulate knowledge. Knowledge in one object is encapsulated if it does not need to be known anywhere else.
For example data records (beans, DTOs, VOs, etc.) don't encapsulate anything, because there is no (business-related) knowledge they exclusively possess. But even proper objects do need to expect some knowledge that the caller possesses, so it's never "perfect".
So long answer: Encapsulation is conceptual, it's in our heads, not necessarily in code.
The short answer is yes, both. This is language dependent.
For instance, Ruby is object-oriented and interpreted -- there is no compilation step (modulo JIT compilers). Smalltalk is also interpreted (at least originally). C++, Modula, Simula, and Java on the other hand are all compiled.
All of these are OOP languages. So if we take encapsulation as an essential characteristic of OOP (and by extension, OOP languages), by observation it must be divorced from compilation.