Skip to content

Commit 605ced1

Browse files
AleksanderGondekJukkaL
authored andcommitted
Fix broken installation on Windows in virtualenv (#4149)
Fixes #4142. Python `site.py` from any virtualenv does not contain many functions added in python 2.7 (see: pypa/virtualenv#355), which results in method `site.getsitepackages` being absent. This commit replaces getsitepackages call with equivalent of `distutils.sysconfig.get_python_lib` which is supported in virtualenv.
1 parent 74ec1b5 commit 605ced1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

mypy/build.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import binascii
1414
import collections
1515
import contextlib
16+
from distutils.sysconfig import get_python_lib
1617
import gc
1718
import hashlib
1819
import json
@@ -229,7 +230,12 @@ def default_data_dir(bin_dir: Optional[str]) -> str:
229230
"""
230231
if not bin_dir:
231232
if os.name == 'nt':
232-
prefixes = [os.path.join(sys.prefix, 'Lib'), os.path.join(site.getuserbase(), 'lib')]
233+
prefixes = [os.path.join(sys.prefix, 'Lib')]
234+
try:
235+
prefixes.append(os.path.join(site.getuserbase(), 'lib'))
236+
except AttributeError:
237+
# getuserbase in not available in virtualenvs
238+
prefixes.append(os.path.join(get_python_lib(), 'lib'))
233239
for parent in prefixes:
234240
data_dir = os.path.join(parent, 'mypy')
235241
if os.path.exists(data_dir):

0 commit comments

Comments
 (0)