Reputation: 1495
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?
Upvotes: 75
Views: 136887
Reputation: 1
if you used pip install virtualenvwrapper-win in windows and used: mkvirtualenv <environment_name> , you can just type 'workon' to display the virtual environments on the command line.
Upvotes: 0
Reputation: 9580
Try
echo $Env:VIRTUAL_ENV
if you are in Windows Powershell (which is for example the default terminal in VSCode).
Taken from Super User at How can I display the contents of an environment variable from the command prompt in Windows 7?
Upvotes: 4
Reputation: 155506
From a shell prompt, you can just do echo $VIRTUAL_ENV
(or in Windows cmd.exe
, echo %VIRTUAL_ENV%
).
From within Python, sys.prefix
provides the root of your Python installation (the virtual environment if active), and sys.executable
tells you which Python executable is running your script.
Upvotes: 30
Reputation: 10090
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
Upvotes: 70
Reputation: 11681
Usually it's set to display in your prompt. You can also try typing in which python
or which pip
in your terminal to see if it points to you venv location, and which one. (Use where
instead of which
on Windows.)
Upvotes: 19