Detect if your script is running inside a virtual environment
Project description
isVirtual is a very simple tool to detect if the current script is within a virtual environment.
Disclaimer
The goal of this project was to play around with the process to publish to Pypi. The code of this module is coming from this stackoverflow thread.
If you find use cases in which it doesn't work please open an issue. I intend to maintain this small package even if it can be seen as "useless".
Install
pip install isvirtual
Usage
This lib can be used within a python script or as a command line.
Python
Simple check:
from isvirtual import is_virtual_env
if __name__ == "__main__":
if is_virtual_env() is True:
print("You are within a virtual environment")
else:
print("You are not in a virtual env")
You can also check if you are specifically in a venv
or virtualenv
environment:
from isvirtual import is_venv, is_virtualenv
if __name__ == "__main__":
if is_venv() is True:
print("You are in a venv")
elif is_virtualenv() is True:
print("You are in a virtualenv")
else:
print("You are not in a virtual env")
You can also get the info from the env coming from pyvenv.cfg
. The sys.prefix
data is added to the original config file:
from isvirtual import is_virtual_env, pyvenv_cfg
if __name__ == "__main__":
if is_virtual_env() is True:
data = pyvenv_cfg()
print(data["home"])
CLI
$ isvirtual
Yes
License
This project is licensed under the terms of the MIT license.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for isvirtual-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea948b96819d7017c6df5371b9035221253c065ceb18c2e99c9549becaeaa767 |
|
MD5 | e9e9c59261cfbed82ed12d3c994c37ea |
|
BLAKE2b-256 | 4a83c75e4990fa81d1d9f1f6025b6272cbecff928c5c1ca4153f96872b86d6da |