at v192 2.8 kB view raw
1Without this patch `virtualenv --python=python2.7 .` fails with an 2error because it notices that the python readline.so is not in the 3same path as python2.7. I assume this is to avoid copying the wrong 4file on systems where it is possible to find incompatible libraries by 5accident. Adding "/nix/store" to the prefix fixes this problem. 6 7A sitecustomize.py is created in the virtualenv which makes libraries 8from the python specified by the --python argument available to the 9virtualenv. For example, this makes readline and sqlite3 available 10when a wrapped python is specified. If no --python argument is passed, 11it will only add the path to the python used when building 12`virtualenv`, which is the unwrapped python, so sqlite3 won't be 13available. 14 15 16diff --git a/virtualenv.py b/virtualenv.py 17index d3e76a7..cb307fa 100755 18--- a/virtualenv.py 19+++ b/virtualenv.py 20@@ -1051,17 +1051,7 @@ def path_locations(home_dir): 21 22 23 def change_prefix(filename, dst_prefix): 24- prefixes = [sys.prefix] 25- 26- if is_darwin: 27- prefixes.extend(( 28- os.path.join("/Library/Python", sys.version[:3], "site-packages"), 29- os.path.join(sys.prefix, "Extras", "lib", "python"), 30- os.path.join("~", "Library", "Python", sys.version[:3], "site-packages"), 31- # Python 2.6 no-frameworks 32- os.path.join("~", ".local", "lib","python", sys.version[:3], "site-packages"), 33- # System Python 2.7 on OSX Mountain Lion 34- os.path.join("~", "Library", "Python", sys.version[:3], "lib", "python", "site-packages"))) 35+ prefixes = ["/nix/store", sys.prefix] 36 37 if hasattr(sys, 'real_prefix'): 38 prefixes.append(sys.real_prefix) 39@@ -1078,6 +1068,8 @@ def change_prefix(filename, dst_prefix): 40 if src_prefix != os.sep: # sys.prefix == "/" 41 assert relpath[0] == os.sep 42 relpath = relpath[1:] 43+ if src_prefix == "/nix/store": 44+ relpath = "/".join(relpath.split("/")[1:]) 45 return join(dst_prefix, relpath) 46 assert False, "Filename %s does not start with any of these prefixes: %s" % \ 47 (filename, prefixes) 48@@ -1190,6 +1182,11 @@ def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear, sy 49 site_filename_dst = change_prefix(site_filename, home_dir) 50 site_dir = os.path.dirname(site_filename_dst) 51 writefile(site_filename_dst, SITE_PY) 52+ wrapper_path = join(prefix, "lib", py_version, "site-packages") 53+ writefile( 54+ join(site_dir, 'sitecustomize.py',), 55+ "import sys; sys.path.append('%s')" % wrapper_path 56+ ) 57 writefile(join(site_dir, 'orig-prefix.txt'), prefix) 58 site_packages_filename = join(site_dir, 'no-global-site-packages.txt') 59 if not site_packages: