diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2016-12-03 11:47:46 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2016-12-30 13:21:26 +0200 |
commit | e9e5c7fc61748b8b7cc73c948556fc9a830c162c (patch) | |
tree | 462d8ee837eb0977bdfac1579af8247eee532718 | |
parent | 58c424a24252bfaebe93617f14f0bac10064c117 (diff) | |
download | astroid-git-e9e5c7fc61748b8b7cc73c948556fc9a830c162c.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.
-rw-r--r-- | astroid/modutils.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/astroid/modutils.py b/astroid/modutils.py index b39d03d9..2854e5f1 100644 --- a/astroid/modutils.py +++ b/astroid/modutils.py @@ -66,10 +66,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) |