Piece
[Python] virtualenv or venv
More Code
2018. 12. 26. 09:05
import sys
# virtualenv
if hasattr(sys, 'real_prefix') \
and hasattr(sys, 'base_prefix') \
and hasattr(sys, 'prefix') \
and sys.base_prefix == sys.prefix:
print("in virtualenv environment")
print("sys.real_prefix", sys.real_prefix)
print("sys.base_prefix", sys.base_prefix)
print("sys.prefix ", sys.prefix)
# venv
if not hasattr(sys, 'real_prefix') \
and hasattr(sys, 'base_prefix') \
and hasattr(sys, 'prefix') \
and sys.base_prefix != sys.prefix:
print("in venv environment")
print("sys.base_prefix", sys.base_prefix)
print("sys.prefix ", sys.prefix)