finish ex0

This commit is contained in:
rvolovoy
2026-11-20 14:42:54 +01:00
parent ee86c25b7b
commit 9893674921
+36 -9
View File
@@ -1,24 +1,51 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
import site
import os
def is_virtual_environment(): def is_virtual_environment():
return sys.prefix != sys.base_prefix return sys.prefix != sys.base_prefix
def main(): def main():
if not is_virtual_environment(): current_python = sys.executable
print("""NOT running in virtual environment. if is_virtual_environment():
Create a virtual environment with: 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 python3 -m venv lab_env
source lab_env/bin/activate source lab_env/bin/activate # On Unix
""") lab_env\Scripts\activate # On Windows
Then run this program again.""")
return
print("""
In virtual env :)
""")
if __name__ == "__main__": if __name__ == "__main__":
main() main()