[Distutils] Get install prefix for module at runtime

Wolodja Wentland wentland at cl.uni-heidelberg.de
Wed Sep 16 20:34:53 CEST 2009

On Wed, Sep 16, 2009 at 17:40 +0200, Wolodja Wentland wrote:
> On Tue, Sep 15, 2009 at 17:38 +0200, Wolodja Wentland wrote:
> > My question is: "How to reliably access data files from a module in
> > foo?"
> > Approach 2 - writing a build.py file at installation time
> > ---------------------------------------------------------
> > 
> > The last question made me think, that Approach 1 works for the three
> > standard installation schemes, but fails miserably if the user decides
> > to do anything fancy.
> I implemented this approach like this:
> --- snip ---
> # -*- coding: UTF-8 -*-
> #!/usr/bin/env python
> from __future__ import with_statement
> import distutils.core as core
> from distutils.command.install import install as _install
> import sys
> import getopt
> import os.path
> class install(_install):
>     """install command
>     This specific install command will create a file 'build_config.py' which
>     contains information on """
>     def run(self): 
>         with open('lib/foo/build_config.py', 'w') as build_fp:
>             build_fp.write('# -*- coding: UTF-8 -*-\n\n')
>             build_fp.write("DATA_DIR = '%s'\n"%(
>                 os.path.join(self.install_data, 'share')))
>             build_fp.write("LIB_DIR = '%s'\n"%(self.install_lib))
>             build_fp.write("SCRIPT_DIR = '%s'\n"%(self.install_scripts))
>         _install.run(self)
> core.setup(name='foo',
>            version='0.1',
>            description='Foo is Bar and Baz',
>            author='Wolodja Wentland',
>            ...
> )
> --- snip ---

I get the following error if i try to install the library:

--- snip ---
reating new virtualenv environment in /home/bar/.virtualenvs/test
  New python executable in /home/bar/.virtualenvs/test/bin/python
  Please make sure you remove any previous custom paths from your /home/bar/.pydistutils.cfg file.
  Installing setuptools...done.....
Unpacking ./dist/foo-0.1.tar.bz2
  Running setup.py egg_info for package from file:///home/bar/src/foo/dist/foo-0.1.tar.bz2
Installing collected packages: foo
  Running setup.py install for foo
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help
    error: option --single-version-externally-managed not recognized
    Complete output from command /home/bar/.virtualenvs/test/bin/python -c "import setuptools; __file__='/tmp/pip-CITX4k-build/setup.py'; execfile('/tmp/pip-CITX4k-build/setup.py')" install --single-version-externally-managed --record /tmp/pip-8lWuFa-record/install-record.txt --install-headers /lib/include:
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]

   or: -c --help [cmd1 cmd2 ...]

   or: -c --help-commands

   or: -c cmd --help

error: option --single-version-externally-managed not recognized

Command /home/bar/.virtualenvs/test/bin/python -c "import setuptools; __file__='/tmp/pip-CITX4k-build/setup.py'; execfile('/tmp/pip-CITX4k-build/setup.py')" install --single-version-externally-managed --record /tmp/pip-8lWuFa-record/install-record.txt --install-headers /lib/include failed with error code 1
Storing complete log in ./pip-log.txt
  Complete output from command /home/bar/.virtualenvs/test/bin/python /usr/lib/python2.5/site-packages/pip-0.4-py2.5.egg/pip.py install -E test dist/foo-0.1.tar.bz2 /home/bar/.virtualenvs/test ___VENV_RESTART___:
Traceback (most recent call last):
  File "/usr/bin/pip", line 5, in <module>
    pkg_resources.run_script('pip==0.4', 'pip')
  File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 448, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 1166, in run_script
    execfile(script_filename, namespace, namespace)
  File "/usr/lib/python2.5/site-packages/pip-0.4-py2.5.egg/EGG-INFO/scripts/pip", line 3, in <module>
  File "/usr/lib/python2.5/site-packages/pip-0.4-py2.5.egg/pip.py", line 926, in main
    return command.main(initial_args, args[1:], options)
  File "/usr/lib/python2.5/site-packages/pip-0.4-py2.5.egg/pip.py", line 258, in main
    restart_in_venv(options.venv, site_packages, complete_args)
  File "/usr/lib/python2.5/site-packages/pip-0.4-py2.5.egg/pip.py", line 1009, in restart_in_venv
    call_subprocess([python, file] + args + [base, '___VENV_RESTART___'])
  File "/usr/lib/python2.5/site-packages/pip-0.4-py2.5.egg/pip.py", line 3643, in call_subprocess
    % (command_desc, proc.returncode))
pip.InstallationError: Command /home/bar/.virtualenvs/test/bin/python /usr/lib/python2.5/site-packages/pip-0.4-py2.5.egg/pip.py install -E test dist/foo-0.1.tar.bz2 /home/bar/.virtualenvs/test ___VENV_RESTART___ failed with error code 1
--- snip ---

What is causing this? How do i handle that error? Is this really the first time
someone faces that problem?

with kind regards

    Wolodja Wentland

P.S And could pip be changed to *only* print the traceback if
--verbose/--debug is given? Including that makes it so much harder  to
find the real error.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20090916/2bb28092/attachment-0001.pgp>

More information about the Distutils-SIG mailing list