Files
python_module_05/ex0/construct.py
T
2026-11-20 14:42:54 +01:00

52 lines
1.1 KiB
Python

#!/usr/bin/env python
import sys
import site
import os
def is_virtual_environment():
return sys.prefix != sys.base_prefix
def main():
current_python = sys.executable
if is_virtual_environment():
environment_path = sys.prefix
venv_name = os.path.basename(environment_path)
site_packages = site.getsitepackages()[0]
print(rf"""
LABORATORY STATUS: The laboratory is sealed
Current Python: {current_python}
Virtual Environment: {venv_name}
Environment Path: {environment_path}
SUCCESS: You are working in an isolated environment!
Safe to install reagents without affecting
the global system.
Reagent installation path:
{site_packages}""")
else:
print(rf"""
LABORATORY STATUS: You are working in the open
Current Python: {current_python}
Virtual Environment: None detected
WARNING: You are in the global environment!
Every reagent you install here leaks into the whole system.
To seal the laboratory, run:
python3 -m venv lab_env
source lab_env/bin/activate # On Unix
lab_env\Scripts\activate # On Windows
Then run this program again.""")
if __name__ == "__main__":
main()