Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
29 lines (26 sloc) 1.13 KB
"""interpreter_startup.py
This script is the target of the PYTHONSTARTUP environment variable, so it runs
each time the Python interpreter is launched in interactive mode. It displays a
warning if there is a virtual environment in the current folder but that virtual
environment is not active.
"""
import os
import sys
WARNING_MSG = '>>> WARNING: virtual environment in this folder is not active'
if sys.prefix == sys.base_prefix: # no virtual environment currently active
if os.path.isfile('env\\Scripts\\activate.bat'):
# there is a virtual environment in this folder, and it is not active,
# but that may be for a web deployment. If the current environment's
# name matches the current folder name, we don't display the warning.
ENVNAME = os.path.basename(sys.base_prefix)
FOLDER = os.path.basename(os.getcwd())
if not ENVNAME.lower() == FOLDER.lower():
print(70*'-')
print(WARNING_MSG)
print(70*'-')
else:
if not sys.prefix.startswith(os.getcwd()):
print(70*'-')
print(WARNING_MSG)
print(' active: ' + sys.prefix)
print(70*'-')