Skip to content

Commit 6a52d4a

Browse files
Fix broken installation on Windows in virtualenv
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 7b65ff5 commit 6a52d4a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mypy/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
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
1920
import os.path
2021
import re
21-
import site
2222
import sys
2323
import time
2424
from os.path import dirname, basename
@@ -229,7 +229,7 @@ def default_data_dir(bin_dir: Optional[str]) -> str:
229229
"""
230230
if not bin_dir:
231231
if os.name == 'nt':
232-
prefixes = [os.path.join(sys.prefix, 'Lib'), os.path.join(site.getuserbase(), 'lib')]
232+
prefixes = [os.path.join(sys.prefix, 'Lib'), os.path.join(get_python_lib(), 'lib')]
233233
for parent in prefixes:
234234
data_dir = os.path.join(parent, 'mypy')
235235
if os.path.exists(data_dir):

0 commit comments

Comments
 (0)