sys.prefix
The folder a running Python treats as its installation; inside a virtual environment it differs from sys.base_prefix.
In more detail
Comparing sys.prefix with sys.base_prefix answers am I in a virtual environment: equal outside one, different inside one. The course uses this pair because it asks Python itself instead of trusting the prompt.
Example
import sys
print(sys.prefix != sys.base_prefix)Related terms
- virtual environment — A self-contained folder with its own Python and its own installed packages, so each project's packages stay separate.
- sys module — The standard library module through which a program asks the running interpreter about itself.
- sys.executable — The full path of the Python interpreter file that is running the current program.
Taught in
- Installing Python On A Mac — Hands-on Python: Complete Video Course & Book
- Installing Python On Linux — Hands-on Python: Complete Video Course & Book
- Where Python Lives: PATH And Versions — Hands-on Python: Complete Video Course & Book
- Virtual Environments — Hands-on Python: Complete Video Course & Book