utils.py 文件源码

python
阅读 74 收藏 0 点赞 0 评论 0

项目:django-develop 作者: pjdelport 项目源码 文件源码
def is_inside_virtual_env():
    """
    Detect whether a Python virtual environment is active.

    This detects environments created using virtualenv, or using Python's built-in venv (PEP 405).
    If true, `sys.prefix` should be the virtual environment's root.

    This implementation only looks at the `sys` module,
    so environment variables like VIRTUAL_ENV do not affect it.

    :rtype: bool
    """
    is_virtualenv = hasattr(sys, 'real_prefix')
    is_venv = hasattr(sys, 'base_prefix') and sys.prefix != sys.base_prefix
    return is_virtualenv or is_venv
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号