summaryrefslogtreecommitdiff
path: root/astroid/modutils.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2016-12-03 11:47:46 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2016-12-03 11:47:46 +0200
commit60743e7e19f319af951948a3fcc2804f980293d3 (patch)
tree82969f1275d42c8f3b8b4ff2044167678d757b4e /astroid/modutils.py
parent84fc589494c8148bef2cee129e3356daa152e382 (diff)
downloadastroid-git-60743e7e19f319af951948a3fcc2804f980293d3.tar.gz
Use sys.base_exec_prefix in case sys.real_prefix is not defined
sys.real_prefix is an addition of the *virtualenv* library, but it is not added when a virtual environment is created with the builtin *venv* library. In the latter's case, sys.base_exec_prefix is the one pointing to the original installation of Python. Now, in case sys.real_prefix is not defined, we fallback to sys.base_exec_prefix.
Diffstat (limited to 'astroid/modutils.py')
-rw-r--r--astroid/modutils.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/astroid/modutils.py b/astroid/modutils.py
index efb7c006..eb7673a6 100644
--- a/astroid/modutils.py
+++ b/astroid/modutils.py
@@ -67,10 +67,18 @@ except DistutilsPlatformError:
if os.name == 'nt':
STD_LIB_DIRS.add(os.path.join(sys.prefix, 'dlls'))
try:
- # real_prefix is defined when running inside virtualenv.
+ # real_prefix is defined when running inside virtual environments,
+ # created with the **virtualenv** library.
STD_LIB_DIRS.add(os.path.join(sys.real_prefix, 'dlls'))
except AttributeError:
- pass
+ # sys.base_exec_prefix is always defined, but in a virtual environment
+ # created with the stdlib **venv** module, it points to the original
+ # installation, if the virtual env is activated.
+ try:
+ STD_LIB_DIRS.add(os.path.join(sys.base_exec_prefix, 'dlls'))
+ except AttributeError:
+ pass
+
if platform.python_implementation() == 'PyPy':
_root = os.path.join(sys.prefix, 'lib_pypy')
STD_LIB_DIRS.add(_root)