Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2@file
3@brief Patches installation
5.. versionadded:: 1.3
6"""
8import os
9import sys
10import shutil
13def fix_python35_dll(path1, path2, force=False):
14 """
15 This function tries to adress a known issue when
16 creating a virtual environment on Windows with Python 3.5
18 @param path1 Python installation
19 @param path2 virtual environment
20 @param force force the replication even if Python version 3.5 is not true
21 @return list of copied assemblies
23 This comes from the following message::
25 ERROR: It thinks sys.prefix is 'c:\\jenkins\\pymy\\py35_actuariat_python'
26 (should be 'c:\\jenkins\\pymy\\py35_actuariat_python\\_virtualenv\\actuariat_python_virpy35_505506092c_505506092c')
27 ERROR: virtualenv is not compatible with this system or executable
28 Note: some Windows users have reported this error when they installed Python for "Only this user"
29 or have multiple versions of Python installed.
30 Copying the appropriate PythonXX.dll to the virtualenv Scripts/ directory may fix this problem.
31 """
32 if not force and sys.version_info[:2] != (3, 5):
33 return []
34 if os.path.isfile(path1):
35 path1 = os.path.dirname(path1)
36 if os.path.isfile(path2):
37 path2 = os.path.dirname(path2)
38 paths2s = [path2]
39 path3 = os.path.join(path2, "Scripts")
40 if os.path.exists(path3):
41 paths2s = [path3]
42 dll = os.listdir(path1)
43 copy = []
44 for f in dll:
45 ext = os.path.splitext(f)[-1]
46 if ext == ".dll":
47 full = os.path.join(path1, f)
48 for path3 in paths2s:
49 to = os.path.join(path3, f)
50 if not os.path.exists(to):
51 copy.append(to)
52 shutil.copy(full, path3)
54 return copy
57if __name__ == "__main__":
58 arg = [_ for _ in sys.argv if ".py" not in _]
59 if len(arg) != 2:
60 print("Usage: {0} <path_to_python35> <virtual_env>".format(
61 os.path.split(__file__)[-1]))
62 else:
63 fix_python35_dll(*arg)