Search code examples
pythonpython-2.7python-venv

how can I find out which python virtual environment I am using?


I have several virtual environment in my computer and sometimes I am in doubt about which python virtual environment I am using. Is there an easy way to find out which virtual environment I am connected to?


Solution

  • You can use sys.prefix to determine which virtualenv you're in.

    import sys
    print(sys.prefix)
    

    from the sys docs

    A string giving the site-specific directory prefix where the platform independent Python files are installed