'Is there a way to retrieve python environment specifications? [duplicate]

So there are some specifications of python environment, which define which whl packages you can install in it: python tag (like cp37), abi tag (like abi3), platform tag (like win32).

So there is a question: is there a way to determine using python or bash/cmd/powershell which environment you are in? Is there some kind of utilities for this? Thank you!



Solution 1:[1]

You can check the system path of your python libraries and using python

import sys
print(sys.path)
print(sys.executable) 

Solution 2:[2]

Assuming you just want the name of the active virtual environment (if any is active), here is a solution using Python: You could find the path of the active Python version like this:

import sys
path = sys.executable

Then extract the venv name.

Edit: or just sys.prefix as MSalters pointed out.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Roshan
Solution 2