[Distutils] virtual env with exec prefix

Hans Meine meine at informatik.uni-hamburg.de
Mon Apr 28 16:00:16 CEST 2008


Hi Ian!

Am Montag, 14. April 2008 20:37:10 schrieb Ian Bicking:
> Hmm... well, does this error only happen when you create a virtualenv
> from within a virtualenv?

No, absolutely not.  It arises whenever python is installed 
with --exec-prefix != --prefix.

> Otherwise, I think there's several things in 
> distutils.sysconfig that need to be adjusted.  That module isn't really
> documented, however, and I suspect there's just a bunch of things that
> will have to be added to over time, not a good general fix.  Or... maybe
> there's some clever way to fix all these, but I'm not sure.

AFAICS, my patch is quite clean - it just extends virtualenv slightly by 
handling exec_prefix and prefix separately.  This affects the same 
entrypoints as before (get_python_inc / get_python_lib) and thus promotes to 
the same changes in higher level functions.

Here's how I tested it:

import distutils.sysconfig, os

for p in range(2):
	for s in range(2):
		print distutils.sysconfig.get_python_lib(p, s)

print "\nMakefile:", distutils.sysconfig.get_makefile_filename()
print "  exists:", os.path.exists(distutils.sysconfig.get_makefile_filename())

You can see the results before/after my virtualenv change here:

*** Without virtualenv: ***
[2] meine at kogspc33:~ -> python test_python_inst.py
/software/python-2.4.4/lib/python2.4/site-packages
/software/python-2.4.4/lib/python2.4
/software/python-2.4.4/SuSE-10.2/lib/python2.4/site-packages
/software/python-2.4.4/SuSE-10.2/lib/python2.4

Makefile: /software/python-2.4.4/SuSE-10.2/lib/python2.4/config/Makefile
  exists: True

*** Trying to create a virtualenv: ***
[2] meine at kogspc33:~ -> virtualenv tmp/ve1
New python executable in tmp/ve1/bin/python
Installing setuptools....
  Complete output from command tmp/ve1/bin/python -c "#!python
\"\"\"Bootstrap setuptoo...




" /software/python-2.4.4/lib/pyt...4.egg:
  error: invalid Python installation: unable to 
open /software/python-2.4.4/lib/python2.4/config/Makefile (No such file or 
directory)
----------------------------------------
...Installing setuptools...done.
Traceback (most recent call last):
  File "/software/python-2.4.4/bin/virtualenv", line 7, in ?
    sys.exit(
  
File "/software/python-2.4.4/lib/python2.4/site-packages/virtualenv-1.0-py2.4.egg/virtualenv.py", 
line 337, in main
    create_environment(home_dir, site_packages=not options.no_site_packages, 
clear=options.clear)
  
File "/software/python-2.4.4/lib/python2.4/site-packages/virtualenv-1.0-py2.4.egg/virtualenv.py", 
line 536, in create_environment
    install_setuptools(py_executable)
  
File "/software/python-2.4.4/lib/python2.4/site-packages/virtualenv-1.0-py2.4.egg/virtualenv.py", 
line 260, in install_setuptools
    extra_env=env)
  
File "/software/python-2.4.4/lib/python2.4/site-packages/virtualenv-1.0-py2.4.egg/virtualenv.py", 
line 396, in call_subprocess
    raise OSError(
OSError: Command tmp/ve1/bin/python -c "#!python
\"\"\"Bootstrap setuptoo...




" /software/python-2.4.4/lib/pyt...4.egg failed with error code 1

*** Unpatched virtualenv: ***
As illustrated above, the installation of setuptools failed, but one can use 
the already-installed python interpreter to run my test program and gets:

[2] meine at kogspc33:~ -> tmp/ve1/bin/python test_python_inst.py
/home/meine/tmp/ve1/lib/python2.4/site-packages
/software/python-2.4.4/lib/python2.4
/home/meine/tmp/ve1/lib/python2.4/site-packages
/software/python-2.4.4/lib/python2.4

Makefile: /software/python-2.4.4/lib/python2.4/config/Makefile
  exists: False

This explains why the setuptools installation failed.

*** Patched virtualenv with real_exec_prefix ***
[2] meine at kogspc33:~ -> . tmp/ve2/bin/activate
(ve2)[2] meine at kogspc33:~ -> python test_python_inst.py
/home/meine/tmp/ve2/lib/python2.4/site-packages
/software/python-2.4.4/lib/python2.4
/home/meine/tmp/ve2/lib/python2.4/site-packages
/software/python-2.4.4/SuSE-10.2/lib/python2.4

Makefile: /software/python-2.4.4/SuSE-10.2/lib/python2.4/config/Makefile
  exists: True

I hope I could convince you to include this crucial fix in virtualenv.

-- 
Ciao, /  /
     /--/
    /  / ANS


More information about the Distutils-SIG mailing list